有两个线程(称为 T1 和 T2)通过 boost 条件变量和互斥锁相互同步,例如:
boost::condition_variable global_cond;
boost::mutex global_mutex;
boost::unique_lock<boost::mutex> lock( global_mutex);
thread1() {
global_cond.notify_one();
code_block_a();
}
tread2() {
global_cond.wait(lock)
code_block_b();
}
假设我可以保证 thread2 先来等待,然后 thread1 将执行通知。
我的问题是,code_block_a() 或 code_block_b() 将首先执行是否具有确定性?