This is the mail archive of the pthreads-win32@sources.redhat.com mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

issue with recursive mutex


Hello,

I apologize if that issue came already up in this list but I can't see
it in the archive.
Got snapshot 2005-01-03 and ran into a deadlock with recursive mutexes.

Looking at the code in pthread_mutex_lock.c and pthread_mutex_unlock.c I
see the following problem.


mutex m;


Thread 0 
--------
m.lock()

Thread 1
--------
m.lock() <- is waiting now

Thread 0
--------
m.lock() <- refcount is now 2 and mx->lock_idx is now 1 !!!!

Thread 0
--------

m.unlock() <- refcount is now 1
m.unlock() <- refcount is now 0 and mx->lock_idx is now 0. 
              no event was send because mx->lock_idx was not less than 0


Thread 1
--------
still locked  :(


After a small modification in pthread_mutex_lock.c, listed below, the
mutex behaved like expected but
indeed this has the cost of sending unnecessary events.
Where does your implementation come from ?

-- 
Best regards,
 Ralf Kubis


ps:

as a first hack I've changed pthread_mutex_lock.c from

  if (mx->kind == PTHREAD_MUTEX_RECURSIVE)
  {
      mx->recursive_count++;
  }

to

  if (mx->kind == PTHREAD_MUTEX_RECURSIVE)
  {
      mx->recursive_count++;
	mx->lock_idx = -1; // assume that there are waiters
  }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]