程序應該從命令行獲取參數,並通過posix線程添加參數。但Xcode成功構建它,但沒有輸出。這段代碼有什麼問題嗎? 謝謝XCode上的POSIX線程添加
#include <iostream>
#include <pthread.h>
using namespace std;
void *Add(void *threadid){
long tid;
tid =(long)threadid;
long sum=0;
sum=sum+tid;
printf("%ld.\n",sum);
pthread_exit(NULL);
}
void *Print(void *threadid){
long tid;
tid =(long)threadid;
printf("%ld.\n",tid);
pthread_exit(NULL);
}
int main (int argc, char const *argv[])
{
if(argc<6){
printf("you need more arguments");
return -1;
}
long real[5];
pthread_t athread,bthread;
for (int x=1;x<=5;x++)
real[x-1]=atol(argv[x]);
for(int y=1;y<=5;y++)
pthread_create(athread[y],NULL,Add,(void *)&real[y]);
for(int y=1;y<=5;y++)
pthread_create(bthread[y],NULL,Print,(void *)&real[y]);
pthread_exit(NULL);
return 0;
}
這個問題是無法解讀的。 「在posix中添加參數」? 「Xcode不提供輸出,地址」輸出/地址是什麼?什麼是'dbll'?至於代碼,顯然,即使是第一件事情就是讓代碼運行。 '#include iostream'甚至不包括所需的括號或引號。 – bames53
對不起,發帖時我忘了括號。他們在真實的代碼 – user1424263
好吧,這很好,但這是問題最少的問題。你可以編輯你的問題來改善它。如果你更清楚你要問什麼,那麼你會更有可能得到有用的答案。 – bames53