【发布时间】:2015-07-21 14:20:47
【问题描述】:
threadA通过这个sn-p
{
global_a = 100; // 1
{
pthread_mutex_lock(&b_mutex)
...
pthread_mutex_unlock(&b_mutex)
} // 2
}
threadB经过这个sn-p
{
{
pthread_mutex_lock(&b_mutex)
...
pthread_mutex_unlock(&b_mutex)
} // 3
int tmp = global_a; // 4
}
并假设从观察者的角度来看,执行顺序确实是
- 线程A --- 1
- 线程A --- 2
- 线程B --- 3
- 线程B --- 4
threadB "int tmp = global_a;" 的代码可以看到 "global_a = 100;" 的 threadA 设置了什么吗?
欢迎提出任何建议。
【问题讨论】:
标签: c++ multithreading synchronization happens-before