A lock on a file is represented by an event object. Process A holds the
lock corresponding with event a. Process B tries to lock, but the lock
of process A blocks that. So B now waits for event a, until it gets
signalled. Now A unlocks, thus signalling event a and closing the handle
afterwards. But A's time slice isn't up yet, so it tries again to lock
the file, before B returned from the wait for a. And here a wrong
condition fails to recognize the situation. It finds the event object,
but since it's recognized as "that's me", it doesn't treat the event as
a blocking factor. This in turn is the allowance to create its own lock
event object. However, the object still exists, since b has still an
open handle to it. So creating the event fails, and rightfully so.
What I don't have is an idea how to fix this problem correctly. I have
to think about that. Stay tuned.