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;
}
从技术上讲,应该有相同行为的两个线程当然可以运行相同的线程函数。 – unwind