-1
私はCで作成したスレッドがpthreadライブラリを使ってpthread_createが受け取った関数を実行していないのを理解しようとしています。ここでPthreadが関数を実行していません
コードです:
void* escucharCPUs (void* arg){
t_Escucha* cpu= (t_Escucha*) arg;
listen(cpu->servidor,cpu->cantConexiones);
printf("estoy esperando CPUs");
t_CPU* newCPU=malloc(sizeof(t_CPU));
while(1){
int cliente2 = recibirCliente(cpu->servidor);
printf("Recibí una conexión en %d!!\n", cliente2);
inicializarCPU(newCPU);
list_add(listaCPUs,newCPU);
}
}
//This is the function that pthread_create recieves.
typedef struct{
int servidor;
int cantConexiones;
}t_Escucha;
//This one above is an auxiliar function for networking, I put it as extra info.
//THIS GOES INSIDE THE MAIN
t_Escucha* CPU;
CPU=malloc(sizeof(t_Escucha));
//And, here is the thread creation
pthread_t hiloEscuchaCPUs;
pthread_attr_init(&atributo);
pthread_attr_setdetachstate(&atributo,PTHREAD_CREATE_DETACHED);
t2=pthread_create(&hiloEscuchaCPUs,&atributo,escucharCPUs,(void*)CPU);
//Is inside the main too
結果は、それが行うには何をしていない場合のpthread_createは以下のように作用すること、です。
私たち(私の全作業チーム)は、何が間違っているのか分かりません。
あなたが提案していることは何でも参考になります、ありがとうございます!この
printf("estoy esperando CPUs\n");
デバッグログがfprintf(stderr, ...)
を使用してstderr
に行くべきのように改行して、各「文字列を」サフィックス(printf()
で使用されている)stdout
をフラッシュする
何が起こりますか?実際に何が起こったのですか? – immibis
あなたが直接観察したことを報告してください。 「ログデータが出てこない」は良いです。 "スレッドは機能を実行しません"はあまり良くありません。これを確認する簡単な方法はありません。 –
関数が実行されていることをどのように知っていますか?より多くのprintfsを追加してください。プロセスをgdbにアタッチし、スレッド関数のブレークを追加してチェックします。 – Jay