Dies ist mein Code, ich habe es mit kompilierte:Multithreaded Linux-Programm nicht mit dem erwarteten Ausgang geben
gcc thread.c -lpthread
Es machte keinen Fehler oder eine Warnung drucken. Aber wenn ich es ausführe, druckt das Programm nichts.
Plattform: Ubuntu 11.10 64-Bit-gcc 4.6.1
Endestatus: 0
Wenn ich es debuggen, fand ich es druckt hello
als ich erwartet hatte.
Dies ist mein Code:
#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;
}