Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fork() support? #4182

Closed
IngwiePhoenix opened this issue Mar 19, 2016 · 4 comments
Closed

fork() support? #4182

IngwiePhoenix opened this issue Mar 19, 2016 · 4 comments

Comments

@IngwiePhoenix
Copy link

Example code: http://timmurphy.org/2014/04/26/using-fork-in-cc-a-minimum-working-example/

Running this with emcc currently gets me the message that it can't fork. I know that in theory nodejs doesn't have actual forking support... but is there a chance to implement it via a mix of child_process+longjmp?

Kind regards, Ingwie

@kripken
Copy link
Member

kripken commented Mar 21, 2016

That sounds quite hard to do. A proper fork needs to do special things with file descriptors, the state of execution, etc., all of which are not practical to support in JS. In practice, I've refactored codebases to avoid fork.

@IngwiePhoenix
Copy link
Author

I see. Well I guess I'll have to do similar. The way fork is used in my end is by a 3rd-party lib which does subprocess handling. Looks like Ill have to give this lib a little makeover with emscripten support, using the child_process APIs.

Thanks for your insights, though! :)

@IngwiePhoenix
Copy link
Author

@juj
Copy link
Collaborator

juj commented Mar 23, 2016

The thing that makes this impossible is that the forked processes are supposed to start executing on the next statement after the fork() call. This is impossible in the current features of JavaScript (unless we use something like emterpreter to emulate code execution), since we are not able to duplicate the callstack of the parent to the forked children so that they'd be executing at the same exact functions and local values on their stack.

Emscripten does have pthreads support for Firefox Nightly and Chrome Canary, so if you don't specifically need a subprocess, but a new thread might do, then you could try using that support instead. It will be a while until that support is mature though and browsers are ready to ship.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants