Don't ask to ask, just ask | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Normally the existence of a file is not a good way for synchronization. But since you want to "remove all threads" anyway, you could have the 'die' routine create a file in a directory common to all threads, and then within each thread test for the existence of the file and if it exists then exit. This would work with 'fork' or separately started scripts as well. In the event that the process is going to restart 'immediately', then the master/startup script must ensure that all threads have completed before unlinking the file and restarting the process. Just a thought, don't use a counter for when to check. Use 'time' to check on the availability of the 'die' file. Check every 5-10 seconds or what is reasonable for your application. I would put a test like this just before waiting on a resource (socket, read, etc.). Also, don't put anything into the 'die' file, since then you could be setting up a potential race condition. If it matters what caused the 'die' then use a separate logging mechanism to record the event. You also may need to set an 'alarm' to break out of wait condition. Just some ideas! Good Luck...Ed "Well done is better than well said." - Benjamin Franklin In reply to Re: removing all threads..
by flexvault
|
|