digitalmars.D.learn - fork/waitpid and std.concurrency.spawn
- Puming (5/5) Jul 22 2014 Is there a fork()/wait() API similar to std.concurrency spawn()?
Is there a fork()/wait() API similar to std.concurrency spawn()? The best thing I've got so far is module core.sys.posix.unistd.fork(), but it seems to only work in posix. Is there a unified API for process level concurrency? ideally with actor and send message support too.
Jul 22 2014
On Tuesday, 22 July 2014 at 07:58:50 UTC, Puming wrote:Is there a fork()/wait() API similar to std.concurrency spawn()? The best thing I've got so far is module core.sys.posix.unistd.fork(), but it seems to only work in posix. Is there a unified API for process level concurrency? ideally with actor and send message support too.You need std.process.
Jul 22 2014
I've only found spawnProcess/spawnShell and the like, which executes a new command, but not a function pointer, like fork() and std.concurrency.spawn does. What is the function that does what I describe? On Tuesday, 22 July 2014 at 10:43:58 UTC, FreeSlave wrote:On Tuesday, 22 July 2014 at 07:58:50 UTC, Puming wrote:Is there a fork()/wait() API similar to std.concurrency spawn()? The best thing I've got so far is module core.sys.posix.unistd.fork(), but it seems to only work in posix. Is there a unified API for process level concurrency? ideally with actor and send message support too.You need std.process.
Jul 22 2014
On Tuesday, 22 July 2014 at 14:26:05 UTC, Puming wrote:I've only found spawnProcess/spawnShell and the like, which executes a new command, but not a function pointer, like fork() and std.concurrency.spawn does. What is the function that does what I describe? On Tuesday, 22 July 2014 at 10:43:58 UTC, FreeSlave wrote:I'm not sure what you're trying to do. Posix fork does not just spawn function, it spawns new process as copy of its parent and continue execution from the point where fork returns. Windows creates processes in some different way, and it seems there is no function with same functionality as Posix fork in WinAPI (by the way you can try to find some implementations on the Internet / use Cygwin / try to use Microsoft Posix Subsystem). I think the reason why phobos does not have functionality you want is that standard library should be platform-agnostic. So instead of emulating things which are not supported by some platform, it just truncates them.On Tuesday, 22 July 2014 at 07:58:50 UTC, Puming wrote:Is there a fork()/wait() API similar to std.concurrency spawn()? The best thing I've got so far is module core.sys.posix.unistd.fork(), but it seems to only work in posix. Is there a unified API for process level concurrency? ideally with actor and send message support too.You need std.process.
Jul 22 2014
OK, I see your point. I didn't know much about windows, so didn't know that fork in windows was so different from posix. This looks reasonable. What I really want is a actor modal similar to std.concurrency, with a similar API and spawn/send/replay semantics, but using processes instead of threads. Actually, generalize this further to fibers and cross machine process, it would be a full blown actor system just like Akka. On Tuesday, 22 July 2014 at 16:11:31 UTC, FreeSlave wrote:On Tuesday, 22 July 2014 at 14:26:05 UTC, Puming wrote:I've only found spawnProcess/spawnShell and the like, which executes a new command, but not a function pointer, like fork() and std.concurrency.spawn does. What is the function that does what I describe? On Tuesday, 22 July 2014 at 10:43:58 UTC, FreeSlave wrote:I'm not sure what you're trying to do. Posix fork does not just spawn function, it spawns new process as copy of its parent and continue execution from the point where fork returns. Windows creates processes in some different way, and it seems there is no function with same functionality as Posix fork in WinAPI (by the way you can try to find some implementations on the Internet / use Cygwin / try to use Microsoft Posix Subsystem). I think the reason why phobos does not have functionality you want is that standard library should be platform-agnostic. So instead of emulating things which are not supported by some platform, it just truncates them.On Tuesday, 22 July 2014 at 07:58:50 UTC, Puming wrote:Is there a fork()/wait() API similar to std.concurrency spawn()? The best thing I've got so far is module core.sys.posix.unistd.fork(), but it seems to only work in posix. Is there a unified API for process level concurrency? ideally with actor and send message support too.You need std.process.
Jul 23 2014
Seems like you need inter process communication. There are many ways to make one. For example, through sockets. You may use D bindings to ZMQ or other library, or just use std.socket. Anyway the process will be represented by the whole program, not just one function as in case of thread.
Jul 23 2014
And there is also Pipe communication in std.process.
Jul 23 2014
OK, I understand your point :-) On Wednesday, 23 July 2014 at 09:05:49 UTC, FreeSlave wrote:Seems like you need inter process communication. There are many ways to make one. For example, through sockets. You may use D bindings to ZMQ or other library, or just use std.socket. Anyway the process will be represented by the whole program, not just one function as in case of thread.
Jul 23 2014