lhmouse/mcfgthread

Deadlock in conditional variable?

Closed this issue · 2 comments

Trzik commented

I have a test with rigorous usage of cond vars that started deadlocking when I switched to mcfgthread implementation. With a little digging, I found that eventually one thread gets stuck in _MCF_cond_wait and the other in _MCF_cond_signal_some_slow.

The signaling thread goes into __MCF_batch_release_common, calls __MCF_keyed_event_signal and ends up in NtReleaseKeyedEvent with NULL (infinite) timeout.

For the wait call, the thread gets stuck in this __MCF_keyed_event_signal call that ends up in the same NtReleaseKeyedEvent call with zero timeout.

status = __MCF_keyed_event_signal(cond, (LARGE_INTEGER[]) { 0 });

I don't understand the code that well, but isn't this line a bug? Shouldn't the __MCF_keyed_event_wait be invoked instead? I did an experimental rebuild of the library with this change and it fixed the deadlock for me. But since I see similar line in event.c, this may be intentional in which case I don't know where the real root cause lies.

Yes that's reasonable explanation. I'm preparing a testcase now.