On Fri, 28 Dec 2007 03:34:02 -0800, George
<George@discussions.microsoft.com> wrote:
while (Sentinel)
Sleep(0); // volatile spin lock
I think even if the original code will result in deadlock. In the
original
MSDN sample, Sleep(0) will sleep forever until there is a signal sent to
the
sleeping thread. But in the original sample, there is no way to trigger
the
thread from waking up.
The sample works by chance because Sentinel happened to false when we
enters
whle loop.
Any comments? If I am wrong, please feel free to correct me. :-)
no, if you check the documentation of Sleep
<quote>
A value of zero causes the thread to relinquish the remainder of its
time slice to any other thread of equal priority that is ready to run.
If there are no other threads of equal priority ready to run, the
function returns immediately, and the thread continues execution.
</quote>
this means the loop will check 'Sentinel' and once it is set to false
by another thread, the loop will terminate.
/ajk