On Wed, Aug 02, 2006 at 05:40:24 +1000, Carlo Sogono wrote:
> I have a thread that requires sleep() to run for 5 mins, but I would
> like this to return when I send a SIGTERM from the command line. SIGTERM
"Programming with POSIX Threads" has this to say on the subject of
threads & signals:
"When writing threaded code, treat signals as Jabberwocks -- curious
and potentially dangerous creatures to be approached with caution,
if at all."
:-)
> Any suggestions welcome. At the moment I might just sleep() every few
> seconds and poll a particular variable but I would prefer sleeping for 5
> or more minutes.
Create a pipe, have your thread call select() with a timeout of five
minutes, have the signal handler write to the pipe. It may not be the
most elegant solution, but it should work.
Cheers,
John
--
"bing-bong. Brimish Rull regret that mumble maz bem dermumble a mir
mumble mumble bimble late. Passengers mizzing to mumble rimble mumble
are advised to momble mar at murmble. Thank you mor mumble mimbling
Brimble mum. bing-bong." -- Gaz on railway announcements
_______________________________________________
coders mailing list
[email protected]
http://lists.slug.org.au/listinfo/coders