Tôi đang cố gắng tạo nhiều luồng mà mỗi chuỗi tính toán số nguyên tố. Tôi đang cố gắng để vượt qua một đối số thứ hai cho một chức năng bằng cách sử dụng tạo thread. Nó tiếp tục ném lên các lỗi.tạo chủ đề - đối số truyền
void* compute_prime (void* arg, void* arg2)
{
đây là chính() của tôi với chuỗi tạo. & primeArray [i] sau & max_prime đang cho tôi lỗi.
for(i=0; i< num_threads; i++)
{
primeArray[i]=0;
printf("creating threads: \n");
pthread_create(&primes[i],NULL, compute_prime, &max_prime, &primeArray[i]);
thread_number = i;
//pthread_create(&primes[i],NULL, compPrime, &max_prime);
}
/* join threads */
for(i=0; i< num_threads; i++)
{
pthread_join(primes[i], NULL);
//pthread_join(primes[i], (void*) &prime);
//pthread_join(primes[i],NULL);
//printf("\nThread %d produced: %d primes\n",i, prime);
printf("\nThread %d produced: %d primes\n",i, primeArray[i]);
sleep(1);
}
lỗi tôi nhận được là:
myprime.c: In function âmainâ:
myprime.c:123: warning: passing argument 3 of âpthread_createâ from incompatible pointer type
/usr/include/pthread.h:227: note: expected âvoid * (*)(void *)â but argument is of type âvoid * (*)(void *, void *)â
myprime.c:123: error: too many arguments to function âpthread_createâ
Nó hoạt động tốt nếu tôi đưa ra đối số thứ hai.
thấy trả lời dưới đây, cũng kiểm tra [link] (https://computing.llnl.gov/tutorials/pthreads/#References) cho một trang web tài liệu tham khảo pthread tốt. – NickO