Skip to content

Commit 233a5d5

Browse files
committed
Ensure join_mutex is locked before being returned.
1 parent de4c2a3 commit 233a5d5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/libstd/sys/unix/freertos/thread.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ impl Thread {
3939

4040
let mut thread = Thread { id: ptr::null_mut(), join_mutex, state };
4141

42+
join_mutex.lock();
43+
4244
let res = xTaskCreate(
4345
thread_start,
4446
name.as_ptr(),
@@ -49,6 +51,8 @@ impl Thread {
4951
);
5052

5153
if res != pdTRUE {
54+
join_mutex.unlock();
55+
5256
if res == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY {
5357
return Err(io::Error::new(io::ErrorKind::Other, "could not allocate required memory for thread"));
5458
} else {
@@ -63,8 +67,6 @@ impl Thread {
6367
let arg = Box::<(Arc<Mutex>, Arc<AtomicUsize>, Box<Box<dyn FnOnce()>>)>::from_raw(arg as *mut _);
6468
let (join_mutex, state, main) = *arg;
6569

66-
join_mutex.lock();
67-
6870
main();
6971
thread_local::cleanup();
7072

0 commit comments

Comments
 (0)