小编Pro*_*kop的帖子

C线程变量在从其他线程声明后具有值

我想用C做一些简单的事情,我很困惑.程序很简单,主要功能是根据作业que结构处理线程.它一次打开4个线程.大约300个线程直到最后.线程函数始终相同但args不同.

这里的孔代码有点长,所以我会粘贴一些零件.

线程正如以下参数一样打开:
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); 
pthread_create(&pth, &attr, dothejob, (void *) varis);
Run Code Online (Sandbox Code Playgroud) 线程称为函数
void *dothejob(void * varis){
unsigned char * arr1;
arr1 = (unsigned char*) calloc(3000000, sizeof (unsigned char));
unsigned char * arr2;
arr2 = (unsigned char*) calloc(3000000, sizeof (unsigned char));
// doing some calculations and comparisons and stuff
unsigned int topten[10];  
// <---- here topten has some values from previous threads, but why ? 
// picking top ten and putting it in the var topten[
free(arr1);
free(arr2);
pthread_detach(pthread_self());
} …
Run Code Online (Sandbox Code Playgroud)

c multithreading pthreads thread-safety

1
推荐指数
1
解决办法
112
查看次数

标签 统计

c ×1

multithreading ×1

pthreads ×1

thread-safety ×1