【发布时间】:2014-12-07 16:52:03
【问题描述】:
假设我有两个线程 T1 和 T1。
线程 T1 将调用 t1_callback(),而 T2 正在调用 t2_callback()。
T some_global_data;
pthread_mutex_t mutex;
void t1_callback()
{
pthread_mutex_lock(&mutex);
update_global_data(some_global_data);
pthread_mutex_unlock(&mutex);
}
void t2_callback()
{
pthread_mutex_lock(&mutex);
update_global_data(some_global_data);
pthread_mutex_unlock(&mutex);
}
案例
t1_callback() 在时间 (t1 - t2) 之间持有锁。
在这段时间 (t1 - t2) 之间,如果 t2_callback 已被调用 10 次。
问题
那么当t1_callback()释放互斥锁时,t2_callback()会执行多少次。
【问题讨论】:
标签: multithreading thread-safety pthreads threadpool