【发布时间】:2014-04-30 14:19:14
【问题描述】:
如果我有
pthread_create(newThread, &attr, threadFunc, arg)
它被多次调用以创建运行threadFunc 的线程,而threadFunc 类似于:
void threadFunc(){ static int x = 0; }
这个x 变量是否在所有线程之间共享?我知道它不在线程的堆栈中,因为它是静态的,并且它位于全局变量所在的位置。
如果没有,并且每个线程都有自己的x,那么就不需要锁了——对吗?
【问题讨论】:
-
如果你想让它成为线程安全的,使用线程本地存储。
标签: c linux multithreading static