From 106385cb9140626166a99d11451e5b4912c602c7 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sun, 8 Jan 2012 11:19:44 -0800 Subject: [PATCH] make spawned fn copy mode so that bare fns can be used --- src/libcore/task.rs | 27 ++++++++++++++++++++++++-- src/test/run-fail/task-spawn-barefn.rs | 11 +++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/test/run-fail/task-spawn-barefn.rs diff --git a/src/libcore/task.rs b/src/libcore/task.rs index 500871ec177..4a966d91fbb 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -110,7 +110,7 @@ Returns: A handle to the new task */ -fn spawn(-f: sendfn()) -> task { +fn spawn(+f: sendfn()) -> task { spawn_inner(f, none) } @@ -139,7 +139,7 @@ A task that sends notification upon termination */ type joinable_task = (task, comm::port); -fn spawn_joinable(-f: sendfn()) -> joinable_task { +fn spawn_joinable(+f: sendfn()) -> joinable_task { let notify_port = comm::port(); let notify_chan = comm::chan(notify_port); let task = spawn_inner(f, some(notify_chan)); @@ -189,6 +189,29 @@ tag task_notification { exit(task, task_result); } +/* +type connected_fn = sendfn(comm::chan, comm::port); +type connected_task = { + port: comm::port, + chan: comm::chan, + task: task +}; +fn spawn_connected(f: connected_fn) + -> connected_fn { + let from_child_port = comm::port(); + let from_child_chan = comm::chan(from_child_port); + let get_to_child_port = comm::port>(); + let get_to_child_chan = comm::chan(to_child_port); + let child_task = spawn(sendfn[move f]() { + let to_child_port = comm::port(); + comm::send(get_to_child_chan, to_child_port); + f(from_child_chan, to_child_port); + }); + let to_child_chan = comm::recv(get_out); + ret {port: from_child_port, chan: to_child_chan, task: child_task}; +} +*/ + /* Section: Operations */ /* diff --git a/src/test/run-fail/task-spawn-barefn.rs b/src/test/run-fail/task-spawn-barefn.rs new file mode 100644 index 00000000000..fe1b926160a --- /dev/null +++ b/src/test/run-fail/task-spawn-barefn.rs @@ -0,0 +1,11 @@ +// error-pattern:Ensure that the child task runs by failing + +fn main() { + // the purpose of this test is to make sure that task::spawn() + // works when provided with a bare function: + task::spawn(startfn); +} + +fn startfn() { + assert str::is_empty("Ensure that the child task runs by failing"); +}