Home > DeveloperSection > Interviews > . How can you have controlled access to the resources, i.e in a thread-safe manner?

Posted on    May-19-2011 8:20 AM

 Visual C++ Visual C++ 
 1 Answer(s)
  1501  View(s)
Rate this:

James Smith

Total Post:79

Posted on    May-19-2011 12:00 AM

You have to have the resources to be controlled with Cmutex object. Then within every object trying to access this resource declare the variable that is of the type CsingleLock/CMultiLock. Calling the lock funtion from this access variable. If you cannot get access in some time, then timeout and continue execution or if you got access perform the functions and do the unlock over the lock variable. Now we have a thread-safe access to the specified resource guarded by the mutex.

Don't want to miss updates? Please click the below button!

Follow MindStick