nspkg / engine / fork.v
25 lines · 22 sloc · 648 bytes · c01b0795d1db56c7bce2539b2c46b110637fdc1a
Raw
1// a worker keeps running V after fork; its collector must forget vanished threads.
2module engine
3
4$if gcboehm ? {
5 #include <gc/gc.h>
6}
7
8fn C.GC_atfork_prepare()
9fn C.GC_atfork_parent()
10fn C.GC_atfork_child()
11
12fn fork_process() i32 {
13 // libgc documents these as no-ops when pthread_atfork handles the collector.
14 // explicit calls also support V builds whose collector has no automatic hooks.
15 $if gcboehm ? {
16 C.GC_atfork_prepare()
17 }
18 child := C.fork()
19 failure := if child < 0 { C.errno } else { 0 }
20 $if gcboehm ? {
21 if child == 0 { C.GC_atfork_child() } else { C.GC_atfork_parent() }
22 }
23 if child < 0 { C.errno = failure }
24 return child
25}
26