On Tue, 26 Sep 2017 12:33:21 -0700, bdug...@matatu.org wrote:
> When I export a function that does a fork() and then
> a react + whenever + IO::Socket::Async.listen in the
> child process, the process only seems to be listening
> on the socket the second time I run the code, i.e. only
> after .precomp has been written.
> 
We don't support calling fork(), because there's no way we reasonably can in 
combination with providing the thread support that we do (and rely on 
internally).

The immediate reason for what you're seeing is probably that precompilation 
uses Proc::Async, which in the turn starts some background threads. A fork() 
call doesn't clone anything other than the thread that forks. So after the 
fork(), the VM is suddenly missing a bunch of its threads, and will very 
possibly deadlock at the next GC run. The lack of a listener is almost 
certainly that the eventloop thread (used for async procs and sockets) was also 
started prior to the fork() and so also goes missing.

Even if that wasn't the case, modern VMs like MoarVM and the JVM start their 
own internal threads for things like optimization and GC, so even a far simpler 
program is very unlikely to successfully fork(), since those internal threads 
will also go missing.

In summary, we can't usefully support fork() in combination with the other 
things we support. What I have done is updated the docs:

https://github.com/perl6/doc/commit/8f9443c3ac8c8d8c33e82457f64a1718f965c769

To not send people down the dead-end road of NativeCalling fork.

Reply via email to