UbuntuのCでスレッドチェーンを実装しようとしています。次のコードをコンパイルすると、ヘッダーファイルを追加したにもかかわらず、これらのスレッドライブラリ関数への未定義の参照のエラーが発生します。セグメンテーション違反エラーも発生します。何故ですか?プログラムのどこにも初期化されていないメモリにアクセスしていません。コードは次のとおりです。
#include <stdio.h>
#include<stdlib.h>
#include <pthread.h>
void* CreateChain(int*);
int main()
{
int num;
pthread_t tid;
scanf("Enter the number of threads to create\n %d",&num);
pthread_create(&tid,NULL,CreateChain,&num);
pthread_join(tid,NULL);
printf("Thread No. %d is terminated\n",num);
return 0;
}
void* CreateChain(int* num )
{
pthread_t tid;
if(num>0)
{
pthread(&tid,NULL,CreateChain,num);
pthread_join(tid,NULL);
printf("Thread No. %d is terminated\n",*num);
}
else
return NULL;
return NULL;
}
次の警告が表示されますが、何らかの理由でScanfプロンプトが表示されません。
よろしく