Solved

synchronizing

Posted on 1998-10-27
6
277 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 150 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.

734 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