Using bInitialOwner combines two steps into one: creating a mutex and getting a mutex. If several people can create mutexes at the same time, the first step may fail, while the second step can be successful.
As the other respondents noted, this is not strictly a problem, since you will get ERROR_ALREADY_EXISTS if someone else creates it first. But then you must distinguish between the cases “could not create or find mutexes” and “could not get mutexes, try again later”, simply using the error code. This will make your code hard to read and easier to corrupt.
In contrast, when bInitialOwner is FALSE, the stream is much simpler:
result = create mutex() if result == error: // die result = try to acquire mutex() if result == error: // try again later else: // it worked!
apenwarr Jun 07 '10 at 5:20 2010-06-07 05:20
source share