Wednesday 15 January 2014

multithreading - Perl Threads - Capture Exit -


I have a code that generates two threads. The first is a system command, which launches an application. The second program monitors. I'm new to perl threads so I have some questions ...

  my $ thr1 = thread-> new (system ($ cmd)); Sleep (FIVEMINUTES); My $ thr2 = Threads-> New (& amp; check); My $ rth1 = $ thr1- & gt; Join (); My $ rth2 = $ thr2- & gt; Join ();   

1) Do I need a second thread to monitor the program? You can think of your sub-regular call & amp; Examine as an infinite, while loop that examines a text file for the creation of the application. Can I just do this:

  my $ thr1 = thread-> new (system ($ CMD)); Sleep (FIVEMINUTES); & Amp; the inspection;   

2) I am trying to figure out what my parents are doing after I run the code. Then after starting the line 1, it will create new thread, sleep, then lay the egg yarn and then wait for that first and wait. This will not execute all my code until it is included in the first joining. Is this true or am wrong? If I am wrong, how does it work?

3) The first thread that launches the application can kill unexpectedly when this happens, I have nothing to catch it and kill the thread. It just says: "Thread 1 abnormally ended: Undefined suburban and main: 65280 myScript.pl was called on line 109." And then there hangs.

What can I do to eliminate the other thread? I need an email before the program ends, which I can do just by calling and email (one of the other subaboutin I've created).

Thanks

First of all,

  My $ thr1 = thread-> new (system ($ cmd));   

should be

  my $ thr1 = thread- & gt; New (sub {system ($ cmd)});   

or just

  my $ thr1 = async {system ($ cmd)};   

You do not need to start the third thread. As you suspect, the main thread and the system is enough to execute.


What if the command is executed in less than five minutes? The fountain takes place with the following signal.

  Use threads; Use thread: share; My $ done: share = 0; My $ thr1 = async {system ($ cmd); Lock ($ done); $ Made = 1; Cond_signal (made $); }; {# Wait for $ timeout until the end of the thread Lock ($); My $ timeout = time () + 5 * 60; 1 while! $ Done & amp; Amp; Cond_timedwait ($ done, $ timeout); If (! $ Made) {... there was a timeout ...}} $ thr1-> Join ();    

No comments:

Post a Comment