#include #include #include #include #include void *wokerT1(void *vargp) { for(int i=0; i<5; i++) { printf("My name is Lvjinzhong\n"); int sleep_time = rand() % 5 + 1; sleep(sleep_time); } return NULL; } void *wokerT2(void *vargp) { for(int i=0; i<5; i++) { printf("My student number is 2024414290124\n"); int sleep_time = rand() % 5 + 1; sleep(sleep_time); } return NULL; } void *wokerT3(void *vargp) { for(int i=0; i<5; i++) { time_t t = time(NULL); printf("Current time %s",ctime(&t)); int sleep_time = rand() % 5 + 1; sleep(sleep_time); } return NULL; } int main() { pthread_t t1,t2,t3; pthread_create(&t1, NULL, wokerT1, NULL); pthread_create(&t2, NULL, wokerT2, NULL); pthread_create(&t3, NULL, wokerT3, NULL); pthread_join(t1, NULL); pthread_join(t2, NULL); pthread_join(t3, NULL); return 0; }