qfedu-linux-advanced-level/day7/nomutex.c

28 lines
522 B
C
Raw Permalink Normal View History

#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
void *printer(void *data)
{
char *msg = (char *)data;
while (*msg)
{
printf("%c", *msg++);
fflush(stdout);
sleep(1);
}
return NULL;
}
int main(int argc, char const **argv)
{
pthread_t tid1, tid2;
pthread_create(&tid1, NULL, printer, "disen666\0");
pthread_create(&tid2, NULL, printer, "lucy888\0");
pthread_join(tid1, NULL);
pthread_join(tid2, NULL);
printf("---over---\n");
return 0;
}