Hacker News new | ask | show | jobs
by pizlonator 11 days ago
You can create threads in the zygote. It doesn't "break down", but sure, there's a bit more work.

My trick for that is that the set of threads that I create pre fork have to be suspendable and resumable, preferably lazily (they resume when they are actually needed). So, the zygotes are sitting with those threads suspended. When they become active, they can do work immediately. They might lazily resume those threads as needed.

There are other idioms for this too.

> Raw fork() is terrible. Instead we need a proper primitive to stop and make a snapshot of a process.

Folks have been saying that it's terrible for as long as I can remember. But it's still there, because it's better than the alternatives

1 comments

> My trick for that is that the set of threads that I create pre fork have to be suspendable and resumable

Well, yes. You need to wait for all the threads to park themselves at safepoints. This can work if you control the whole runtime, and you don't use something that creates threads behind your back.

This is actually why I've always been interested in a better fork(), it has a lot of parallels with stop-the-world needed for GCs.

> Folks have been saying that it's terrible for as long as I can remember. But it's still there, because it's better than the alternatives

I don't think we have alternatives? Except maybe ptrace()?