This is the mail archive of the
mailing list for the pthreas-win32 project.
RE: mutex_lock on solaris vs. winnt
- To: 'Hung Huynh' <Hung dot Huynh at emw dot ericsson dot se>, pthreads-win32 at sourceware dot cygnus dot com
- Subject: RE: mutex_lock on solaris vs. winnt
- From: "Bossom, John" <John dot Bossom at Cognos dot COM>
- Date: Thu, 27 Jul 2000 12:46:32 -0400
pthread_mutex is implemented on Win32 using Win32 primitive
locking mechanisms. These primitives are inherently recursive
in nature (i.e. the same thread may re-acquire the lock multiple
times... internally they keep a count of the # of times it has
Microsoft decided to do this to prevent a thread from deadlocking
itself. There are non-standard versions of PThreads on various
UNIX platforms that allow you to declare a mutex as recursive.
However, it is recommended that if you want PORTABLE code, that
you do not rely on recursive mutex support... Since you have this
code on UNIX and had attempted to acquire a mutex lock twice in the
same thread, you've basically deadlocked your thread permanently...
I would recommend you re-organize your code such that you do not
re-acquire the same mutex...
From: Hung Huynh [mailto:Hung.Huynh@emw.ericsson.se]
Sent: Thursday, July 27, 2000 12:37 PM
Subject: mutex_lock on solaris vs. winnt
I'm trying to port some code from unix (solaris) to windows nt.
The code uses pthread mutexes to create a binary semaphore for
reading (many-at-a-time) and writing (one-at-a-time).
I have just found out that if you in unix do pthread_unix_lock
twice on the same mutex, and in the same process, you will lock. But
trying to do the same thing in windows nt (with pthread-win32 released
won't give the same behaviour. Is this because the WaitForSingleObject
will allow multiple locks in the same process? Should it be like this or
something that is just not yet implemented in pthread-win32?
As you can tell I'm a newbie, and i'll appreciate very much any
on this. Thank you in advance.