【发布时间】:2011-09-06 21:22:24
【问题描述】:
我们对 pthread 使用一次性初始化,如下所示:
/* define a statically initialized pthread_once_t variable */
pthread_once_t once_var = PTHREAD_ONCE_INIT;
/* we call pthread_once function in threads */
int pthread_once(pthread_once_t *once_control, void (*init)(void));
当多个线程要改变pthread_once_t变量的状态时,我们是否需要一个互斥锁来保护它?
【问题讨论】: