Can this posix style CV be done using a semaphore (which can remember a
signal)?.
Harish
-----Original Message-----
From: Pavel Lebedinsky [mailto:xxxxx@microsoft.com]
Sent: Thursday, August 27, 2009 3:28 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Driver contract changes in Win 7
Consider two synchronization (auto reset) events which protect a
shared
buffer like in a consumer/producer fashion:
Reader thread:
R1)Read from the buffer
R2)PulseEvent (readEvent,0,TRUE) // Signal writer that reading is
done
R3)WaitForSingleObject(writeEvent)
R4)goto A1
Writer thread:
W1)Write to the buffer
W2)PulseEvent(writeEvent,0,TRUE) // Signal read thread that writing is
done
W3)WaitForSingleObject(readEvent) // Wait until reader did reading
W4)Goto W1
With atomic set and wait this will work as expected:
R1-R2-R3-W4-W1-W2-W3-R4-R1-R2-R3-etc.
Without atomic set and wait, the order may become:
R1-R2-W4-W1-W2-R3-W3 -> deadlock
This is the “missed pulse” problem that often comes up when people
try to implement something similar to POSIX condition variables
using win32 events. Some people attempt to solve it using
SignalObjectAndWait (which internally uses the Wait=TRUE trick)
but this is still not 100% reliable (even pre-win7) because an APC
can temporarily remove the thread from its wait, causing it to
miss a pulse anyway. (This is why PulseEvent is now deprecated,
by the way).
Drivers can disable APCs so technically it’s possible to construct
a kernel-mode example that seems to work reliably on previous
OS versions and suffers from the missed pulse problem on win7.
However, I think that behavior in this case was not well-defined
to begin with, so it’s not something that drivers should be relying on.
–
Pavel Lebedinsky/Windows Kernel Test
This posting is provided “AS IS” with no warranties, and confers no
rights.
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer