From 94260fb91d3e8a11f39eafc1c21bc974713db166 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Wed, 17 Aug 2011 11:44:35 -0700 Subject: Using move-mode for spawn thunks to avoid race conditions. --- src/lib/task.rs | 9 +++++---- src/lib/test.rs | 5 ++++- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'src/lib') diff --git a/src/lib/task.rs b/src/lib/task.rs index 434092b524a..d010afc5217 100644 --- a/src/lib/task.rs +++ b/src/lib/task.rs @@ -75,21 +75,22 @@ fn set_min_stack(stack_size : uint) { rustrt::set_min_stack(stack_size); } -fn _spawn(thunk : fn() -> ()) -> task { +fn _spawn(thunk : -fn() -> ()) -> task { spawn(thunk) } -fn spawn(thunk : fn() -> ()) -> task { +fn spawn(thunk : -fn() -> ()) -> task { spawn_inner(thunk, none) } -fn spawn_notify(thunk : fn() -> (), notify : _chan) +fn spawn_notify(thunk : -fn() -> (), notify : _chan) -> task { spawn_inner(thunk, some(notify)) } // FIXME: make this a fn~ once those are supported. -fn spawn_inner(thunk : fn() -> (), notify : option<_chan>) +fn spawn_inner(thunk : -fn() -> (), + notify : option<_chan>) -> task_id { let id = rustrt::new_task(); diff --git a/src/lib/test.rs b/src/lib/test.rs index 5b6d6b34c97..2b4d1f2714a 100644 --- a/src/lib/test.rs +++ b/src/lib/test.rs @@ -336,13 +336,16 @@ fn run_test(test: &test_desc, to_task: &test_to_task) -> test_future { // we've got to treat our test functions as unsafe pointers. This function // only works with functions that don't contain closures. fn default_test_to_task(f: &fn()) -> task_id { + /* fn run_task(fptr: *mutable fn() ) { configure_test_task(); // Run the test (*fptr)() } let fptr = ptr::addr_of(f); - ret task::_spawn(bind run_task(fptr)); + */ + //ret task::_spawn(bind run_task(fptr)); + task::spawn(f) } // Call from within a test task to make sure it's set up correctly -- cgit 1.4.1-3-g733a5