Есть ли способ при использовании pthread.h
в GCC Linux для хранения переменных, локальных для функции потока:
int i = 42; // global instance of i
int main() {
pthread_t threads[2];
long t;
pthread_create(&threads[t], NULL, ThreadFunction, (void *) t;
pthread_create(&threads[t], NULL, ThreadFunction2, (void *) t;
}
Интересно, есть ли параметр в функции POSIX, создающий новый поток и сохраняющий переменные локальными:
void *ThreadFunction(void *threadid)
{
int i=0;
i++; // this is a local instance of i
printf("i is %d", i); // as expected: 1
}
void *ThreadFunction2(void *threadid)
{
i += 3; // another local instance -> problem
}
Где впоследствии i
равно 42. Даже если я определил i
ранее, я хочу, чтобы это i
не было в моих темах.