Solved

synchronizing

Posted on 1998-10-27
6
273 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
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Handling string inputs in C/Linux 23 168
sum13 challenge 24 77
either24  challenge 19 84
FizzBuzz challenge 9 73
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: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now