Re: MSDN volatile sample



Hi ajk,


Could you provide a link to your quoted Sleep method description please?

I am reading from,

http://msdn2.microsoft.com/en-us/library/d00bd51t(VS.80).aspx

not the same as you quoted.


regards,
George

"ajk" wrote:

On Fri, 28 Dec 2007 03:34:02 -0800, George
<George@xxxxxxxxxxxxxxxxxxxxxxxxx> 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


.



Relevant Pages

  • Re: MSDN volatile sample
    ... Could you provide a link to your quoted Sleep method description please? ... this means the loop will check 'Sentinel' and once it is set to false ...
    (microsoft.public.vc.language)
  • Re: MSDN volatile sample
    ... Could you provide a link to your quoted Sleep method description please? ... Windows doesn't even have signals (except emulated in the posix ... this means the loop will check 'Sentinel' and once it is set to false ...
    (microsoft.public.vc.language)
  • cant get out of infinite while loop
    ... To get into the infinite loop, I write to a file the "on" status ... writing switch on ... ready to sleep for 10 seconds ... or die "Problem passing files to the bridge directory...$!"; ...
    (comp.lang.perl.misc)
  • Re: question about thread scheduling
    ... I doubt you will need to mess with the system tick to get what ... I will try what you suggested, the reason that I didn't use the sleep ... If the NN run in a different thread as the control loop ... Sleepputs your thread to sleep for 3 timer ticks and ...
    (microsoft.public.windowsce.platbuilder)
  • Re: question about thread scheduling
    ... I will try what you suggested, the reason that I didn't use the sleep method ... If the NN run in a different thread as the control loop ... Sleepputs your thread to sleep for 3 timer ticks and ...
    (microsoft.public.windowsce.platbuilder)