Subj : Re: mutex problem To : comp.programming.threads From : Torsten Robitzki Date : Fri Jun 17 2005 10:20 am LinuxGuy wrote: > Hi, > > I have one thread which locks the mutex in one function for certain > purose. but while executing that portion I am calling another function > from same thread and want to update some data but, data I want to > update may create problem as earlier function may be using that. > in short how to use same mutex for locking twice in > same thread. means I want to update same data structure in another > function while other function using it by loking mutex > > any suggestion is welcome Just don't lock the mutex in that second function. For the case that the second function requires that the mutex is locked, write a wrapper for the second function that just locks the mutex and then call that function. void f1() { mutex.lock(); /* what ever */ f2_impl(); } void f2() { mutex.lock(); f2_impl(); } void f2_impl() { /* what ever */ } This pattern is quit easy. Just split every function that needs a lock and can be called with or without holding the lock. regards Torsten .