[PATCH] new mutex implementation 2. posting

Thomas Pfaff tpfaff@gmx.net
Tue Sep 17 02:34:00 GMT 2002


This patch contains a new mutex implementation.

The advantages are:

- Same code on Win9x and NT. Actual are critical sections used on NT and
  kernel mutexes on 9x.
- Posix compliant error codes.
- State is preserved after fork as it should.
- Supports both errorchecking and recursive mutexes.
- Should be at least as fast as critical sections.

Unfortunately the pthread_mutex_trylock call requires
InterlockedCompareExchange that is not available on Win95.
See my winbase patch for a workaround.

Just like critical sections it will use a counter and a semaphore to block
other threads. The semaphore is only used when at least one thread is
waiting, otherwise a kernel transition is not needed.

With these mutexes the default type has changed from recursive to
errorchecking, this is also the default on all other pthread platforms
that i know (except Linux where the default is FAST where you will not get
an EDEADLOCK on locking twice, it WILL deadlock instead).

With my previous 2 patches and this one i was able to build and run a
threaded perl that has passed all tests (to be true it failed 3 but these
were really not pthread related).

2002-08-15  Thomas Pfaff <tpfaff@gmx.net>

	* include/pthread.h: Added define for errorchecking mutexes,
	changed default mutex type.
	* thread.cc (pthread_mutex::pthread_mutex): New implemented.
	(pthread_mutex::~pthread_mutex): Ditto.
	(pthread_mutex::Lock): Ditto.
	(pthread_mutex::TryLock): Ditto.
	(pthread_mutex::UnLock): Ditto.
	(pthread_mutex::Destroy): New method.
	(pthread_mutex::SetOwner): Ditto.
	(pthread_mutex::fixup_after_fork): Preserve state after fork.
	(__pthread_mutex_destroy): Call pthread_mutex::Destroy to destroy
	mutex.
	(__pthread_mutexattr_settype): Allow errorchecking and recursive
	types.
	* thread.h (pthread_mutex::criticalsection): Removed.
	(pthread_mutex::lock_counter): New member.
	(pthread_mutex::recursion_counter): Ditto.
	(pthread_mutex::owner): Ditto.
	(pthread_mutex::type): Ditto.
	(pthread_mutex::Destroy): New method.
	(pthread_mutex::SetOwner): Ditto.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pthread_mutex.patch
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20020917/aab100f5/attachment.ksh>


More information about the Cygwin-patches mailing list