https://bugs.winehq.org/show_bug.cgi?id=46099
--- Comment #21 from Zebediah Figura z.figura12@gmail.com --- (In reply to Fabian Maurer from comment #20)
We need to be able to very that, at the exact point that the thread is queued on select(), the value still matches the comparand.
What do you mean?
If we check that the value matches before queueing, we can get a race of the form:
thread A: checks value, still equal to comparand thread B: sets value thread B: perform wake thread A: queue self
We need to prevent such a wake from occurring between the time thread A checks the value for the last time, and the time it queues itself.
The Linux kernel manages this with futexes by locking the queue and then (effectively) atomically comparing the value and queueing the thread. We can't really use this approach, since we can't be reading process memory from the wineserver.
My idea was to split queueing and waiting into two separate operations for futexes, though now I'm wondering if perhaps a CS might be better here.