Re: threading question
scott mcfadden <nospam.smcfadden@criticaltech.com> wrote:
C# has a easy way of waking another thread (Thread.Interupt). Does
C++ /MFC have a nice way of checking the status of another thread and
if it is sleeping, to wake it?
If a thread is in alertable wait state (put there by SleepEx,
WaitForSingleObjectEx and so on) it can be interrupted by queing an
asynchronous procedure call on it with QueueUserAPC. That's how
Thread.Interrupt is implemented: whenever threads block they are put
into an alertable state; to interrupt, QueueUserAPC is used to call a
function that throws ThreadInterruptedException.
This is a generic approach suitable when implementing a framework. For
specific scenarios, usually a simpler ad hoc solution can be designed.
Note that Thread.Interrupt does not "check the status" of another
thread: it queues the interrupt request unconditionally, the other
thread will be interrupted as soon as it enters the wait state,
regardless of whether or not it was sleeping at the time of Interrupt
call.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925