This commit is contained in:
2026-05-16 12:08:49 +08:00
parent f679b67969
commit 119f0e7b3a
16 changed files with 1114 additions and 0 deletions

50
AI-work/task61.c Normal file
View File

@@ -0,0 +1,50 @@
#include <pthread.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void *workerT1(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 *workerT2(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 *workerT3(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()
{
srand(time(NULL));
pthread_t t1, t2, t3;
pthread_create(&t1, NULL, workerT1, NULL);
pthread_create(&t2, NULL, workerT2, NULL);
pthread_create(&t3, NULL, workerT3, NULL);
pthread_join(t1, NULL);
pthread_join(t2, NULL);
pthread_join(t3, NULL);
return 0;
}