【发布时间】:2016-11-10 14:14:34
【问题描述】:
有两个线程(称为 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() 将首先执行是否具有确定性?
【问题讨论】:
-
一般?不,在你的代码中?谁知道。也许如果你发布了它。
标签: c++ multithreading boost-mutex