Tech
2022. 4. 24.
[concurrency] 조건변수
어떤 조건을 만족하지 않을 때는 프로세스를 대기 상태로 두고, 조건이 만족되면 대기중인 프로세스를 실행하고 싶을 때가 있을 것이다. use std::sync::{Arc, Mutex, Condvar};use std::thread;fn child(id: u64, p: Arc, Condvar)>) { let (lock, cvar) = &*p; let mut started = lock.lock().unwrap(); while !*started { started = cvar.wait(started).unwrap(); //https://doc.rust-lang.org/std/sync/struct.Condvar.html } println!("Child {}", id);}fn p..