Browse Source

Workaround waitpid deadlock by making ptrace state thread local

Jeremy Soller 3 years ago
parent
commit
c51aec1af6
1 changed files with 9 additions and 2 deletions
  1. 9 2
      src/platform/redox/ptrace.rs

+ 9 - 2
src/platform/redox/ptrace.rs

@@ -39,10 +39,17 @@ impl State {
     }
 }
 
-static STATE: Once<State> = Once::new();
+#[thread_local]
+static mut STATE: Option<State> = None;
 
 pub fn init_state() -> &'static State {
-    STATE.call_once(|| State::new())
+    // Safe due to STATE being thread_local
+    unsafe {
+        if STATE.is_none() {
+            STATE = Some(State::new())
+        }
+        STATE.as_ref().unwrap()
+    }
 }
 pub fn is_traceme(pid: pid_t) -> bool {
     File::open(