Это мой код, я скомпилировал его:
gcc thread.c -lpthread
Не печаталось ни ошибок, ни предупреждений. Но когда я его запускаю, программа ничего не печатает.
Платформа: Ubuntu 11.10, 64-битная gcc 4.6.1
Статус выхода: 0
Когда я отлаживал его, я обнаружил, что он печатает hello
, как и ожидал.
Это мой код:
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
void *loopPrint(void *ptr)
{
char *p = (char *)ptr;
while (1)
{
printf("%s\n", p);
}
}
void *pClock(void *ptr)
{
sleep(3);
exit(0);
}
int main()
{
pthread_t showMsg, clock;
int main_pth, wait_pth;
char *msg = "Hello";
main_pth = pthread_create(&showMsg, NULL, loopPrint, (void *)msg);
wait_pth = pthread_create(&clock, NULL, pClock, NULL);
pthread_join(main_pth, NULL);
pthread_join(wait_pth, NULL);
return 0;
}