sim: Fix fork for multithreaded simulations
Review Request #3475 - Created May 20, 2016 and updated
| Information | |
|---|---|
| Jason Lowe-Power | |
| gem5 | |
| default | |
| Reviewers | |
| Default | |
Changeset 11483:d7066cc30459 --------------------------- sim: Fix fork for multithreaded simulations Previously, when forking, the thread states were inconsistent. Now, after a fork, we re-create all the needed threads. This allows you to run in *single-threaded* mode after a fork. There would need to be a way to migrate the threads to conintue in threaded mode.
LGTM. Minor note below.
-
src/sim/simulate.cc (Diff revision 1) -
It might be safer to use an initial PID that will definitely not be a valid PID (e.g. -1) rather than 0, which is a valid PID (just unlikely that it would ever be used for a user process).
Posted (May 26, 2016, 7:19 a.m.)
Thanks for looking into this! Forking a multi-threaded simulation is very scary. If I remember my POSIX right, the behaviour after a fork of a multi-threaded program is undefined (IIRC, you are supposed to call exec without passing go and collecting $200). This is one of the reasons I didn't handle it when I originally implemented forking (and I didn't need it at the time). I would suggest that you instead make sure that all threads are joined before forking (e.g., by joining them after draining).
