(* Show chdir and threads. *) let phase = ref 0 let phase_lock = Mutex.create () let phase_cond = Condition.create () let wait_phase n = Mutex.lock phase_lock; while !phase != n do Condition.wait phase_cond phase_lock done; Mutex.unlock phase_lock let mark_phase n = Mutex.lock phase_lock; phase := n; Condition.signal phase_cond; Mutex.unlock phase_lock let thread_a () = wait_phase 1; Unix.chdir "a"; mark_phase 2; wait_phase 3 let thread_b () = (* Execution starts here. *) mark_phase 1; wait_phase 2; Printf.printf "result dir: %S\n" (Unix.getcwd ()); mark_phase 3 let () = let a = Thread.create thread_a () in let b = Thread.create thread_b () in Thread.join a; Thread.join b