Robert Collins rbcollins@cygwin.com
Wed Mar 19 09:52:00 GMT 2003

On Mon, 2003-03-17 at 19:17, Thomas Pfaff wrote:
> 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.

Enabled by default. Sure, as long as they aren't turned off again, or
someone builds without them to get 386 support... Please, use the
compatible test, it won't alter the code much. You can test for <0 and
>0 safely.

> 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).

Well there is a limit either way. I don't see any pragmatic difference.

> > 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.

It's about type safety. Please, correct it.


GPG key available at: <http://users.bigpond.net.au/robertc/keys.txt>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20030319/23b0f4ff/attachment.sig>

More information about the Cygwin-patches mailing list