From 64f798492c5d7abfef8be9837ae0703cda43b48e Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Fri, 30 Jun 2017 10:49:18 -0600 Subject: Fix thread safety issues in aio, chdir, and wait tests They have four problems: * The chdir tests change the process's cwd, which is global. Protect them all with a mutex. * The wait tests will reap any subprocess, and several tests create subprocesses. Protect them all with a mutex so only one subprocess-creating test will run at a time. * When a multithreaded test forks, the child process can sometimes block in the stack unwinding code. It blocks on a mutex that was held by a different thread in the parent, but that thread doesn't exist in the child, so a deadlock results. Fix this by immediately calling std::process:exit in the child processes. * My previous attempt at thread safety in the aio tests didn't work, because anonymous MutexGuards drop immediately. Fix this by naming the SIGUSR2_MTX MutexGuards. Fixes #251 --- test/sys/test_wait.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/sys/test_wait.rs') diff --git a/test/sys/test_wait.rs b/test/sys/test_wait.rs index d8ac94e4..2e28d9e7 100644 --- a/test/sys/test_wait.rs +++ b/test/sys/test_wait.rs @@ -6,6 +6,9 @@ use libc::exit; #[test] fn test_wait_signal() { + #[allow(unused_variables)] + let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); + match fork() { Ok(Child) => pause().unwrap_or(()), Ok(Parent { child }) => { @@ -19,6 +22,9 @@ fn test_wait_signal() { #[test] fn test_wait_exit() { + #[allow(unused_variables)] + let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); + match fork() { Ok(Child) => unsafe { exit(12); }, Ok(Parent { child }) => { -- cgit v1.2.3