"A value of INFINITE indicates that the suspension should not time out."
So, if the suspension doesn't time out, how _does_ the thread resume
running?
I can see reasons for infinite waiting in some of the other
thread-suspension functions, such as WaitForSingleObject or SleepEx. In
those functions, there are other situations built into the functions
that will cause them to return. But can Sleep(Infinite) ever return? Can
the sleeping thread be signaled from some other thread to make it resume
running, either by making Sleep return, or by causing an exception to
send execution somewhere else?
If it can't, then is there any reason to call it? Wouldn't it be easier
to simply terminate the thread?
--
Rob
> So, if the suspension doesn't time out, how _does_ the thread
> resume running?
It doesn't. So never pass INFINITE to Sleep() at all.
> can Sleep(Infinite) ever return?
No.
> Can the sleeping thread be signaled from some other thread
> to make it resume running
Not when Sleep(INFINITE) is used, no. SleepEx() can do that, though.
> If it can't, then is there any reason to call it?
There is never any reason to call Sleep(INFINITE).
> Wouldn't it be easier to simply terminate the thread?
No. That is a completely separate and unrelated operation.
Gambit
I think INFINITE was introduced for SleepEx, WaitForSingleObject etc.,
but to avoid a special case INFINITE can be used for Sleep, too, even if
I see no reason to use it there. After all if INFINITE (which equals
$FFFFFFFF) was not allowed for Sleep, people could still pass values
like $7FFFFFFF instead, sleeping for 24 days, which is nearly as silly
as INFINITE.
--
Jens Gruschel
http://www.pegtop.net
-Bill
I use Sleep in the execute methods of my threads all the time. In these
cases my threads are busily working and I do Sleep(0) where appropriate. I
have other threads that do things continuously but not as importantly (like
acquiring images for display) where I do Sleeps of up to 100 between
decoding frames to keep the CPU usage low. So I'd say short Sleeps are very
useful.
Though I've never used TSimpleEvents before (probably because I mainly use
D5) they seem to be more useful in synchronizing between threads or other
asynchronous code. Mostly my threads are running until the app is closed so
waiting up to 100ms isn't a great deal (especially when acquiring and
decoding a frame may take as long as my Sleep). Though I see the usefulness
of a TSimpleEvent, I don't see how they can be used for delays.