Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

synchronizing

Posted on 1998-10-27
6
Medium Priority
?
280 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 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

596 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