实验三 Linux 多线程编程
发布时间
阅读量:
阅读量
任务 1:编写名为 task31.c 的程序,主线程需生成三个对等线程 T1、T2、T3,每个线程通过循环执行五次 printf 输出操作,并在两次循环之间随机暂停 1 至 5 秒。主线程需等待所有对等线程完成任务后,再结束整个进程。各个对等线程的输出内容如下:
T1:显示“My name is <您的姓名 xxx>”
T2:显示“My student number is <您的学号 xxx>”
T3:显示“Current time <当前时间,包含年月日时分秒>
task31.c
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<unistd.h>
#include<pthread.h>
void* thread_name(){
for(int i=0;i<5;i++){
printf("My name is \n");
int time = rand()%5+1;
sleep(time);
}
}
void* thread_num(){
for(int
全部评论 (0)
还没有任何评论哟~
