中易网

急!有三个线程ID分别是A、B、C,请有多线编程实现,在屏幕上循环打印10次ABCABC… 用linux下的c实现!

答案:3  悬赏:40  
解决时间 2021-03-14 13:53
给出思路就行!
最佳答案
gcc Thread.c -o Thread -lpthread
#include <stdio.h>
#include <pthread.h>
void main()
{
pthread_t t1 , t2 , t3;
void *p_msg(void *);
pthread_create(&t1,NULL,p_msg,(void * )"A ");
pthread_create(&t2,NULL,p_msg,(void * )"B ");
pthread_create(&t3,NULL,p_msg,(void * )"C");
pthread_join(t1, NULL);
pthread_join(t2, NULL);
pthread_join(t3, NULL);
}
void *p_msg(void *m)
{
int i;
for(i = 0 ; i < 10 ; i ++)
{
printf("%s",m);
fflush(stdout);
sleep(1);
}
return NULL;
}
全部回答
//文件:Thread.c //编译命令:gcc Thread.c -o Thread -lpthread #include <stdio.h> #include <pthread.h> void main() { pthread_t t1 , t2 , t3; void *p_msg(void *); pthread_create(&t1,NULL,p_msg,(void * )"A "); pthread_create(&t2,NULL,p_msg,(void * )"B "); pthread_create(&t3,NULL,p_msg,(void * )"C\n"); pthread_join(t1, NULL); pthread_join(t2, NULL); pthread_join(t3, NULL); } void *p_msg(void *m) { int i; for(i = 0 ; i < 10 ; i ++) { printf("%s",m); fflush(stdout); sleep(1); } return NULL; }
java代码 public class main { public static void main(string[] args){ data data=new data(); new threada("a",data).start(); new threadb("b",data).start(); new threadc("c",data).start(); }
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
觉得穷人越来越难翻身了,没机遇和贵人相助几
在Flash MX中如何将“影片剪辑”插入到“场
地利生鲜家苑路店我想知道这个在什么地方
金星小区地址在什么地方,想过去办事
求都市的小说,男主因一些意外变成女的,但是
兴化有没有种植甘庶的
鸡和鸭共有200只,鸡的脚数比兔的脚数多160只
1988年农历四月初八晚上6点多出生女五行缺什
爱奇艺的会员账号借一个不被已永久封禁
qq超级会员和黄钻我开到了6 想知道花了多少钱
工伤赔偿金社保局每月赔偿金是多少
三亚京海汽车服务中心我想知道这个在什么地方
描写同学的好句
什么饵料能让鱼吃了有饥饿,过会鱼疯狂寻食
吸烟可以提神吗
推荐资讯
三星除了卖手机还卖什么
1、水中的小鱼游来游去.(改写成拟人句) 2、哼
武胜猪肝面总店在哪里啊,我有事要去这个地方
汇享健康生活馆NO.116地址在什么地方,想过去
考试第一名,打一个数字,0-9
警校几年啊?
抚顺周边什么地方能烧烤还能带狗
目前对于初学者哪些古董最有收藏价值
我想做房产销售,不知从哪开始入手学??谢谢
打LOL掉帧怎么办啊 一进游戏一百多帧 玩一会
励志路/白鹿路(路口)我想知道这个在什么地方
石板镇卫生院这个地址在什么地方,我要处理点
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?