Sunil Keshava(deleted)
|
mutex locked by two threads
|
Sunil Keshava(deleted)
06/05/2010 5:34 AM
post56107
|
mutex locked by two threads
Hello,
I have a static mutex defined within a class and it is initialized it as follows:
pthread_mutex_t my_class::mutex = PTHREAD_MUTEX_INITIALIZER;
This mutex is used within my_class member functions. These member function can be called by different thread (by simply
creating an object of type my_class) and to mutex is used to maintain synchronization between threads.
While testing, I noticed that that there were few cases were more than one thread lseemed to lock the mutex. Here is an
example:
at Time1: Thread 1 locks mutex
at Time2: thread 2 locks mutex
at Time3: thread 2 unlock mutex
at Time4: thread 1 unlocks mutex
I was expecting thread 2 would lock mutex only after thread 1 had unlocked. But something seems to be going wrong.
Another point to note is that, this behaviour does not occur always. It occured about once every 500 times the mutex
lock was called.
Any help/information on this would be useful.
Thanks
Sunil
|
|
|