Subj : Re: mutex problem To : comp.programming.threads From : Torsten Robitzki Date : Fri Jun 17 2005 11:14 am LinuxGuy wrote: > Hi Torsten, Hi Stranger, > Thanks for help.. you will get more idea about my problem from > following one.. > > I have thread a class is not a thread. Do you have one instance of a class aka an object? And two threads want to change the state of that single object? > class a > { > public : > > void threadFunction() > { > mutex.lock() > here doing some processing and > updating "sampleString" > mutex.unlock() > } So do you call anotherFunction() from here? > > void anotherFuntion() > { > here I want to update "sampleString" and this function will be > called from any other cpp file but at that time "threadFunction may > have locked the resources. From what othere source file the function is call doesn't matter. It's important to know if that function will be called by othere threads. > and using "sampleString" can you please > tell me how to protect data or to execute functions without affecting > each others data Assumed that your one and only mutex is used to guard an invariant of an object and that sampleString is not part of that invariant. So that you can change the value of sampleString independant from othere states of an object, that one solution is to use a second mutex just to protect sampleString from concurrent accesses. Don't know if this helps nor if I understood your problem. regards Torsten .