From 7d756e44a96c1e28f63cab1ea328d01984ac07d2 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 13 Jun 2014 16:03:41 -0700 Subject: rustrt: Reorganize task usage Most of the comments are available on the Task structure itself, but this commit is aimed at making FFI-style usage of Rust tasks a little nicer. Primarily, this commit enables re-use of tasks across multiple invocations. The method `run` will no longer unconditionally destroy the task itself. Rather, the task will be internally re-usable if the closure specified did not fail. Once a task has failed once it is considered poisoned and it can never be used again. Along the way I tried to document shortcomings of the current method of tearing down a task, opening a few issues as well. For now none of the behavior is a showstopper, but it's useful to acknowledge it. Also along the way I attempted to remove as much `unsafe` code as possible, opting for safer abstractions. --- src/libnative/task.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/libnative/task.rs') diff --git a/src/libnative/task.rs b/src/libnative/task.rs index 8b7c8e61bc3..0b863d9f694 100644 --- a/src/libnative/task.rs +++ b/src/libnative/task.rs @@ -92,8 +92,7 @@ pub fn spawn_opts(opts: TaskOpts, f: proc():Send) { let mut f = Some(f); let mut task = task; task.put_runtime(ops); - let t = task.run(|| { f.take_unwrap()() }); - drop(t); + drop(task.run(|| { f.take_unwrap()() }).destroy()); bookkeeping::decrement(); }) } -- cgit 1.4.1-3-g733a5