Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - mutex locked by two threads: (2 Items)
   
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
RE: mutex locked by two threads  
It is highly unlikely that mutex is being locked by multiple threads.

Could you post your test code?


Thanks,

Aleksandar

-----Original Message-----
From: Sunil Keshava [mailto:community-noreply@qnx.com]
Sent: Sat 6/5/2010 5:34 AM
To: momentics-community
Subject: 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



_______________________________________________

QNX Momentics Community Support
http://community.qnx.com/sf/go/post56107


Attachment: Text winmail.dat 3.07 KB