Solved

synchronizing

Posted on 1998-10-27
6
275 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 155
windows 10 how make picture as desktop background 2 62
maxBlock challenge 30 128
Doc'in system (example?) BA 7 106
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

808 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