This is the mail archive of the
cygwin-patches@cygwin.com
mailing list for the Cygwin project.
Re: [PATCH] add support for PTHREAD_MUTEX_NORMAL
- From: Thomas Pfaff <tpfaff at gmx dot net>
- To: "Cygwin (Robert Collins)" <rbcollins at cygwin dot com>
- Cc: cygwin-patches at cygwin dot com
- Date: Mon, 17 Mar 2003 09:17:05 +0100 (Westeuropäische Normalzeit)
- Subject: Re: [PATCH] add support for PTHREAD_MUTEX_NORMAL
On Thu, 13 Mar 2003, Cygwin (Robert Collins) wrote:
> This:
>
> if (1 == InterlockedIncrement ((long *)&lock_counter))
>
> is not safe. You can only check for equal to 0, less than 0, and greater
> than 0 with InterlockedIncrement | Decrement.
>
The xadd based inline interlocked functions in winbase.h are now enabled
by default, so it is valid to test for 1 at this point.
It looks much cleaner to me to start a counter at 0 not at -1.
And the code now supports UINT_MAX instead of INT_MAX waiting
threads (even if INT_MAX threads are only academicical i see no reason to
add a limit here).
> Secondly, IIRC lock_counter should be long, so the (long *) typecasting
> isn't needed.
IMHO it should be unsigned since it makes no sense to have negative
counter values. In practice it doesn't make any difference because there
are not greater or smaller equations in the code.
Thomas