Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

ISAI student,

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
in thread removing all threads.. by ISAI student

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2024-04-19 08:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found