Ich habe Probleme beim Erstellen eines Threads innerhalb eines Threads. Ich muss thread1 erstellen und thread1 tut "etwas" sowie create thread2, die etwas anderes tun.Wie erstellen Sie einen Thread, der einen anderen Thread in C-Programmierung erstellt?
meinen Code:
#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;
}
Technisch können zwei Threads, die das gleiche Verhalten haben sollten, natürlich die gleiche Thread-Funktion ausführen. – unwind