?
Solved

synchronizing

Posted on 1998-10-27
6
Medium Priority
?
279 Views
Last Modified: 2013-11-20
hi, regards!
I am using VC++ Document file called coninfo.rec to store
some configuration information. i used cmapstringtoob classes to serialzie information. I am using 2 different threads in my application. I had a function which access this document information. Those 2 threads may access this function. In order to avoid this function been called by a thread when other  one is using it, please help me how to synchronize. Will the critical section methods apply ?

the function name is Proccess_Query(.....)

the to other thread routines that calls this function is
threadfunc1(....) & threadfunc2(...)

Kindly give the detailed reply. I can increase the points
for convincing answers.

thanks!
r sundar r
0
Comment
Question by:sunraj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1323933
This is a duplicate - -I have placed an answer in the other one.

Sunraj - you should delete this one.
0
 
LVL 2

Expert Comment

by:cyrilbdt
ID: 1323934
If Proccess_Query is member function of some class add member variable of type CMutex. If it is not plase global variable of this type.

void Proccess_Query(<your args>)
{
 CSingleLock lock(&m_Mutex, true);
 ....
}

see CSingleLock::CSingleLock for secind argument.
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1323935
cyrilbdt - This was clearly a duplicate question, you should not post answers to duplicates because then customer service has to delete one.  This can be a pain, would you like me to notify them to delete this second copy?
0
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 

Author Comment

by:sunraj
ID: 1323936
mr.cyrilbdt's,

I have read in Ralph Davis book, that in multithreading
environment we should use only CRITICAL_SECTION methods for
synchronizing.
So please give your detailed answer.
The above answer is not convincing. Anyway thanks!
0
 

Author Comment

by:sunraj
ID: 1323937
mr.cyrilbdt's,

I have read in Ralph Davis book, that in multithreading
environment we should use only CRITICAL_SECTION methods for
synchronizing.
So please give your detailed answer.
The above answer is not convincing. Anyway thanks!
For your kind information, Process_query is a global function.
0
 
LVL 1

Accepted Solution

by:
TheGrinch earned 300 total points
ID: 1323938
Define your critical secion variable...
   CRITICAL_SECTION  m_Sync;
.and initialize it once...
   InitializeCriticalSection ( &m_Sync );

Then do this at every call of Process_Query()...
   EnterCriticalSection ( &m_Sync );
   Process_Query();
   LeaveCriticalSection ( &m_Sync );

This insures that only one thread at a time will be using Process_Query().
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question