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
