好的我正试图传递一对数字struct来pthread_create运行pthread.但是我传递的数字和调用函数时得到的数字是不同且随机的
这里是 struct
struct Pairs {
long i,j;
};
Run Code Online (Sandbox Code Playgroud)
内部主要
void main()
{
long thread_cmp_count = (long)n*(n-1)/2;
long t,index = 0;
struct Pairs *pair;
pair = malloc(sizeof(struct Pairs));
cmp_thread = malloc(thread_cmp_count*sizeof(pthread_t));
for(thread = 0;(thread < thread_cmp_count); thread++){
for(t = thread+1; t < n; t++){
(*pair).i = thread;
(*pair).j = t;
pthread_create(&cmp_thread[index++], NULL, Compare, (void*) pair);
}
}
for(thread= 0;(thread<thread_cmp_count); thread++){
pthread_join(cmp_thread[thread], NULL);
}
free(cmp_thread);
}
Run Code Online (Sandbox Code Playgroud)
和功能比较
void* Compare(void* pair){
struct Pairs *my_pair = (struct …Run Code Online (Sandbox Code Playgroud)