I am new to writing multi-threaded Perl applications, but I am not a total n00b to perl... well maybe just a kinda n00b ;)
In the past when I wanted to implement a timeout event, I used alarms. But I read in the docs that there can only be one alarm running, so that will not do for my multi-threaded program with several worker threads all needing their own alarm concurrently.
The tasks my worker threads are performing is running bash test scripts that they receive from an action queue, and reporting the status of tests to a finished queue. The scripts run time ranges from minutes to several hours, but the stdout should change for each script relatively often. If the stdout does not change for a given action for a significant period of time, then the bash script has frozen, so i need to record the fail and run the next script.
Here is the general idea of the approach I would take in a single process program.
eval { open (HANDLE, " $cmdstring |"); alarm $timeout; while (HANDLE) { #process and record info from command's stdout alarm $timeout; #update alarm } alarm 0; }; if ($@) { #timeout occurred #record the fail } else { # do normal stuff }
I have thought of writing system times to a shared variable for each worker, and then run another thread to work as a watchdog for the other processes, and kill threads as they hang, but this would be very messy and I would have to create new threads to fill the place, which could result in some memory nightmares and other issues...
In reply to Thread Safe alarms? by Pocadotty
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |