Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Fork and creating a thread exits the process

by fluks (Novice)
on Aug 01, 2020 at 11:17 UTC ( [id://11120188]=note: print w/replies, xml ) Need Help??


in reply to Re: Fork and creating a thread exits the process
in thread Fork and creating a thread exits the process

The obvious problem here is that creating a thread or forking a subprocess completes immediately and the main thread continues, then exits at the end of the script while the children are waiting at sleep 300. When the main thread exits the process, Windows kills the other threads.

The main thread didn't continue because the part of the code I showed was running in an indefinite loop. And nothing in the child processes or in the worker threads was executed either.

For a solution, try either wait/waitpid or the ->join() method in threads instead of detaching your worker threads.

I think I tried threads without detaching them. And since the part of the program is in an indefinite loop, I don't want to wait the processes to finish because the loop needed to be fast.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11120188]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (8)
As of 2024-03-28 12:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found