@@ -38,7 +38,7 @@ impl Thread {
38
38
let join_mutex = Arc :: new ( Mutex :: new ( ) ) ;
39
39
let state = Arc :: new ( AtomicU8 :: new ( PENDING ) ) ;
40
40
41
- let arg = box ( join_mutex . clone ( ) , state . clone ( ) , p) ;
41
+ let arg = box ( Arc :: clone ( & join_mutex ) , Arc :: clone ( & state ) , p) ;
42
42
43
43
let name = name. unwrap_or_else ( || CStr :: from_bytes_with_nul_unchecked ( b"\0 " ) ) ;
44
44
@@ -56,9 +56,7 @@ impl Thread {
56
56
) ;
57
57
58
58
if res != pdTRUE {
59
- if thread. state . load ( SeqCst ) == PENDING {
60
- drop ( Box :: from_raw ( arg) ) ;
61
- }
59
+ drop ( Box :: from_raw ( arg) ) ;
62
60
63
61
if res == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY {
64
62
return Err ( io:: Error :: new (
@@ -79,8 +77,7 @@ impl Thread {
79
77
* Box :: from_raw ( arg as * mut ( Arc < Mutex > , Arc < AtomicU8 > , Box < dyn FnOnce ( ) > ) ) ;
80
78
81
79
join_mutex. lock ( ) ;
82
-
83
- state. store ( RUNNING , SeqCst ) ;
80
+ state. compare_and_swap ( PENDING , RUNNING , SeqCst ) ;
84
81
85
82
main ( ) ;
86
83
thread_local:: cleanup ( ) ;
@@ -160,7 +157,9 @@ impl Thread {
160
157
unsafe {
161
158
assert ! ( self . id != xTaskGetCurrentTaskHandle( ) ) ;
162
159
163
- while self . state . load ( SeqCst ) == PENDING { }
160
+ while self . state . load ( SeqCst ) == PENDING {
161
+ Self :: yield_now ( )
162
+ }
164
163
165
164
// Just wait for the thread to finish, the rest is handled by `Drop`.
166
165
self . join_mutex . lock ( ) ;
0 commit comments