diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-01-04 12:02:02 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-01-05 22:28:23 -0800 |
| commit | 9c8813f006d9955196b5e9c21c06df8a8b1a3f15 (patch) | |
| tree | 2f524eb47c3a2dcbda91a52257f3c20fa3626902 /src/libnative | |
| parent | b432e82515f4cc145cf41bbcb92ff9b874b23afe (diff) | |
Guarantee that native tasks wait for children
There was a scheduling race where a child may not increment the global task count before the parent exits, and the parent would then think that there are no more tasks left.
Diffstat (limited to 'src/libnative')
| -rw-r--r-- | src/libnative/task.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/libnative/task.rs b/src/libnative/task.rs index 661358a64e9..5a1ef5c836e 100644 --- a/src/libnative/task.rs +++ b/src/libnative/task.rs @@ -72,6 +72,11 @@ pub fn spawn_opts(opts: TaskOpts, f: proc()) { let task = task; let ops = ops(); + // Note that this increment must happen *before* the spawn in order to + // guarantee that if this task exits it will always end up waiting for the + // spawned task to exit. + bookeeping::increment(); + // Spawning a new OS thread guarantees that __morestack will never get // triggered, but we must manually set up the actual stack bounds once this // function starts executing. This raises the lower limit by a bit because @@ -88,7 +93,6 @@ pub fn spawn_opts(opts: TaskOpts, f: proc()) { let mut ops = ops; ops.stack_bounds = Some((my_stack - stack + 1024, my_stack)); - bookeeping::increment(); let mut f = Some(f); let mut task = task; task.put_runtime(ops as ~rt::Runtime); |
