diff options
| author | Ben Blum <bblum@andrew.cmu.edu> | 2013-07-16 17:28:46 -0400 |
|---|---|---|
| committer | Ben Blum <bblum@andrew.cmu.edu> | 2013-07-20 05:12:04 -0400 |
| commit | 7ad7911222f0395dd2babaf12410fb15c9aa938f (patch) | |
| tree | a983cd583eb539a5d0781915be39032d74aeabc4 /src/libstd/task/spawn.rs | |
| parent | 21831458500b1a5c78fe6aeccab5412fac701d9f (diff) | |
| download | rust-7ad7911222f0395dd2babaf12410fb15c9aa938f.tar.gz rust-7ad7911222f0395dd2babaf12410fb15c9aa938f.zip | |
Add watched and indestructible spawn modes.
Diffstat (limited to 'src/libstd/task/spawn.rs')
| -rw-r--r-- | src/libstd/task/spawn.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 9734a41ba3b..2150c0c5ac2 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -671,6 +671,7 @@ pub fn spawn_raw(opts: TaskOpts, f: ~fn()) { fn spawn_raw_newsched(mut opts: TaskOpts, f: ~fn()) { let child_data = Cell::new(gen_child_taskgroup(opts.linked, opts.supervised)); + let indestructible = opts.indestructible; let child_wrapper: ~fn() = || { // Child task runs this code. @@ -692,7 +693,11 @@ fn spawn_raw_newsched(mut opts: TaskOpts, f: ~fn()) { }; // Should be run after the local-borrowed task is returned. if enlist_success { - f() + if indestructible { + unsafe { do unkillable { f() } } + } else { + f() + } } }; @@ -700,13 +705,13 @@ fn spawn_raw_newsched(mut opts: TaskOpts, f: ~fn()) { let sched = Local::unsafe_borrow::<Scheduler>(); rtdebug!("unsafe borrowed sched"); - if opts.linked { + if opts.watched { let child_wrapper = Cell::new(child_wrapper); do Local::borrow::<Task, ~Task>() |running_task| { ~running_task.new_child(&mut (*sched).stack_pool, child_wrapper.take()) } } else { - // An unlinked task is a new root in the task tree + // An unwatched task is a new root in the exit-code propagation tree ~Task::new_root(&mut (*sched).stack_pool, child_wrapper) } }; @@ -848,6 +853,7 @@ fn test_spawn_raw_simple() { fn test_spawn_raw_unsupervise() { let opts = task::TaskOpts { linked: false, + watched: false, notify_chan: None, .. default_task_opts() }; @@ -878,6 +884,7 @@ fn test_spawn_raw_notify_failure() { let opts = task::TaskOpts { linked: false, + watched: false, notify_chan: Some(notify_ch), .. default_task_opts() }; |
