-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module d.gc.fork; | ||
|
||
import core.stdc.pthread; | ||
|
||
void setupFork() { | ||
if (pthread_atfork(prepare, parent, child) != 0) { | ||
import core.stdc.stdlib, core.stdc.stdio; | ||
printf("pthread_atfork failed!"); | ||
exit(1); | ||
} | ||
} | ||
|
||
void prepare() { | ||
/** | ||
* Before forking, we want to take all the locks. | ||
* This ensures that no other thread holds on GC | ||
* resources while forking, and would find itself | ||
* unable to release them in the child. | ||
* The order in which locks are taken is important | ||
* as taking them in the wrong order will cause | ||
* deadlocks. | ||
* | ||
* FIXME: At the moment, we only take the lock for | ||
* the collection process. This ensures we | ||
* can use the fork/exec pattern safely, but | ||
* it will nto leave the GC in a usable state | ||
* in the child. | ||
*/ | ||
import d.gc.collector; | ||
collectorPrepareForFork(); | ||
} | ||
|
||
void parent() { | ||
import d.gc.collector; | ||
collectorPostForkParent(); | ||
} | ||
|
||
void child() { | ||
import d.gc.collector; | ||
collectorPostForkChild(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters