我無法在c中執行pthreads程序。請告訴我以下程序有什麼問題。我既沒有收到任何錯誤,也沒有預期輸出。以下pthread程序有什麼問題?
void *worker(void * arg)
{
int i;
int *id=(int *)arg;
printf("Thread %d starts\n", *id);
}
void main(int argc, char **argv)
{
int thrd_no,i,*thrd_id,rank=0;
void *exit_status;
pthread_t *threads;
thrd_no=atoi(argv[1]-1);
thrd_id= malloc(sizeof(int)*(thrd_no));
threads=malloc(sizeof(pthread_t)*(thrd_no));
for(i=0;i<thrd_no;i++)
{
rank=i+1;
thrd_id[i]=pthread_create(&threads[i], NULL, worker, &rank);
}
for(i=0;i<thrd_no;i++)
{
pthread_join(threads[i], &exit_status);
}
}
呃,其中一個,你的程序會建立儘可能多的警告,因爲它有行。考慮添加一些包含並整理警告;編譯器很擅長告訴你有關令人討厭的驚喜,你應該注意它的警告。 – zmccord 2012-04-22 07:15:02