0
スレッド内にスレッドを作成できません。私はthread1を作成する必要があり、thread1は「何か」を行い、何か他のことをするthread2を作成します。Cプログラミングで別のスレッドを作成するスレッドをどのように作成しますか?
私のコード:
#include <pthread.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
void *msg1(void *ignored)
{
void *msg2(void *ignored)
{
printf("this is thread2");
}
pthread_t thread;
int thread2;
thread2 = pthread_create(&thread, NULL, msg2, NULL);
return 0;
}
int main()
{
pthread_t thread;
int thread1;
thread1 = pthread_create(&thread, NULL, msg1, NULL);
return 1;
}
技術的には、同じ振る舞いを持つ2つのスレッドはもちろん、同じスレッド関数を実行できます。 – unwind