about summary refs log tree commit diff
path: root/src/libtest
diff options
context:
space:
mode:
authorAaron Turon <aturon@mozilla.com>2014-12-14 00:05:32 -0800
committerAaron Turon <aturon@mozilla.com>2014-12-18 23:31:52 -0800
commita27fbac86849e07a0a6c746869d8f78319bd3a16 (patch)
treef17d75fcdd4d353f5ff919e491a5fc71252c0ef1 /src/libtest
parent13f302d0c5dd3a88426da53ba07cdbe16459635b (diff)
downloadrust-a27fbac86849e07a0a6c746869d8f78319bd3a16.tar.gz
rust-a27fbac86849e07a0a6c746869d8f78319bd3a16.zip
Revise std::thread API to join by default
This commit is part of a series that introduces a `std::thread` API to
replace `std::task`.

In the new API, `spawn` returns a `JoinGuard`, which by default will
join the spawned thread when dropped. It can also be used to join
explicitly at any time, returning the thread's result. Alternatively,
the spawned thread can be explicitly detached (so no join takes place).

As part of this change, Rust processes now terminate when the main
thread exits, even if other detached threads are still running, moving
Rust closer to standard threading models. This new behavior may break code
that was relying on the previously implicit join-all.

In addition to the above, the new thread API also offers some built-in
support for building blocking abstractions in user space; see the module
doc for details.

Closes #18000

[breaking-change]
Diffstat (limited to 'src/libtest')
-rw-r--r--src/libtest/lib.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs
index 044a4a173c6..56af8785a76 100644
--- a/src/libtest/lib.rs
+++ b/src/libtest/lib.rs
@@ -1126,7 +1126,7 @@ pub fn run_test(opts: &TestOpts,
             let mut reader = ChanReader::new(rx);
             let stdout = ChanWriter::new(tx.clone());
             let stderr = ChanWriter::new(tx);
-            let mut cfg = thread::cfg().name(match desc.name {
+            let mut cfg = thread::Builder::new().name(match desc.name {
                 DynTestName(ref name) => name.clone().to_string(),
                 StaticTestName(name) => name.to_string(),
             });
@@ -1137,11 +1137,11 @@ pub fn run_test(opts: &TestOpts,
                 cfg = cfg.stderr(box stderr as Box<Writer + Send>);
             }
 
-            let result_guard = cfg.with_join(testfn);
+            let result_guard = cfg.spawn(move || { testfn.invoke(()) });
             let stdout = reader.read_to_end().unwrap().into_iter().collect();
             let test_result = calc_result(&desc, result_guard.join());
             monitor_ch.send((desc.clone(), test_result, stdout));
-        });
+        }).detach();
     }
 
     match testfn {