当前位置: 首页 > news >正文

免费网站怎么注册手机企业管理app软件

免费网站怎么注册,手机企业管理app软件,无代码编程的应用场景,怎样设计个人网站1.思维导图 2.有一个隧道#xff0c;长1000m#xff0c;有一辆高铁#xff0c;每秒100米#xff1b;有一辆快车#xff0c;每秒50米#xff1b;要求模拟这两列火车通过隧道的场景。 1程序代码#xff1a; #include stdio.h #include string.h #i…1.思维导图 2.有一个隧道长1000m有一辆高铁每秒100米有一辆快车每秒50米要求模拟这两列火车通过隧道的场景。 1程序代码 #include stdio.h #include string.h #include unistd.h #include stdlib.h #include sys/types.h #include sys/stat.h #include fcntl.h #include pthread.h #include semaphore.h #include wait.h #include signal.h #include sys/socket.h #include arpa/inet.h #include sys/socket.h #include sys/ipc.h #include sys/sem.h #include semaphore.h #include sys/msg.h #include sys/shm.h #include sys/un.htypedef struct sockaddr_in addr_in_t; typedef struct sockaddr addr_t; typedef struct sockaddr_un addr_un_t;#define LENGTH 1000 //隧道的长度typedef struct {const char *name;int speed;int position; }Train;void *simulate_train(void *arg) {Train *train (Train *)arg;while (train-position LENGTH) {train-position train-speed; // 火车前进if (train-position LENGTH)train-position LENGTH; // 防止超出隧道长度printf(%s正在 %d 米处\n, train-name, train-position);sleep(1); }printf(%s已出隧道\n, train-name);return NULL; } int main(int argc, const char *argv[]) {pthread_t high_speed_thread, fast_train_thread;// 初始化两列火车Train high_speed_train {高铁, 100, 0};Train fast_train {快车, 50, 0};// 创建线程模拟火车运行pthread_create(high_speed_thread, NULL, simulate_train, high_speed_train);pthread_create(fast_train_thread, NULL, simulate_train, fast_train);// 等待两列火车完成运行pthread_join(high_speed_thread, NULL);pthread_join(fast_train_thread, NULL);printf(两列火车都已出隧道\n);return 0; }2运行效果 3.有一条隧道长1000m有一辆高铁每秒100米有一辆快车每秒50米有一辆慢车每秒25米模拟它们通过隧道的场景要求高铁最先过隧道快车其次慢车最后。 1程序代码 #include stdio.h #include string.h #include unistd.h #include stdlib.h #include sys/types.h #include sys/stat.h #include fcntl.h #include pthread.h #include semaphore.h #include wait.h #include signal.h #include sys/socket.h #include arpa/inet.h #include sys/socket.h #include sys/ipc.h #include sys/sem.h #include semaphore.h #include sys/msg.h #include sys/shm.h #include sys/un.htypedef struct sockaddr_in addr_in_t; typedef struct sockaddr addr_t; typedef struct sockaddr_un addr_un_t;#define LENGTH 1000 // 隧道长度typedef struct {const char *name; int speed; int position; int order; //火车顺序 } Train;pthread_mutex_t mutex; pthread_cond_t cond; int current_order 1; // 当前允许进入隧道的火车顺序void *simulate_train(void *arg) {Train *train (Train *)arg;pthread_mutex_lock(mutex);while (train-order ! current_order) {pthread_cond_wait(cond, mutex);}pthread_mutex_unlock(mutex);while (train-position LENGTH) {train-position train-speed; // 火车前进if (train-position LENGTH) {train-position LENGTH; // 防止超出隧道长度}printf(%s正在%d米处\n, train-name, train-position);sleep(1); // 模拟每秒前进}printf(%s已出隧道\n, train-name);pthread_mutex_lock(mutex);current_order;pthread_cond_broadcast(cond);pthread_mutex_unlock(mutex);return NULL; }int main(int argc, const char *argv[]) {pthread_t id1,id2,id3;// 初始化三列火车Train high_speed_train {高铁, 100, 0, 1};Train fast_train {快车, 50, 0, 2};Train slow_train {慢车, 25, 0, 3};// 创建线程模拟火车运行pthread_create(id1, NULL, simulate_train, high_speed_train);pthread_create(id2, NULL, simulate_train, fast_train);pthread_create(id3, NULL, simulate_train, slow_train);// 等待所有线程完成pthread_join(id1, NULL);pthread_join(id2, NULL);pthread_join(id3, NULL);printf(所有火车都已出隧道\n);return 0; }2运行效果 4.使用条件变量实现一个生产消费模型pv模型。生产者线程每秒生成2个苹果消费者线程每3秒消费5~9个苹果。 1程序代码 #include stdio.h #include string.h #include unistd.h #include stdlib.h #include sys/types.h #include sys/stat.h #include fcntl.h #include pthread.h #include semaphore.h #include wait.h #include signal.h #include sys/socket.h #include arpa/inet.h #include sys/socket.h #include sys/ipc.h #include sys/sem.h #include semaphore.h #include sys/msg.h #include sys/shm.h #include sys/un.htypedef struct sockaddr_in addr_in_t; typedef struct sockaddr addr_t; typedef struct sockaddr_un addr_un_t;#define MAX_APPLES 100 //定义仓库最大容量 int apple_count 0; //当前苹果的数量//使用条件变量 pthread_mutex_t mutex; pthread_cond_t cond;//生产者线程 void* producer(void* arg) {while(1){pthread_mutex_lock(mutex);//生产苹果if(apple_count2 MAX_APPLES){apple_count 2;printf(生产者生产2个苹果目前苹果总数为:%d\n,apple_count);}else{printf(仓库已满生产者等待生产中...\n);}//唤醒消费者线程pthread_cond_signal(cond);pthread_mutex_unlock(mutex);sleep(1);}return NULL; }//消费者线程 void* consumer(void* arg) {while(1){pthread_mutex_lock(mutex);int consumption rand() % 5 5; //随机消费5~9个苹果while(apple_count consumption){printf(消费者想要消费 %d 个苹果但是只剩 %d 个苹果等待...\n,consumption,apple_count);pthread_cond_wait(cond,mutex); //等待生产者生产}//消费苹果apple_count - consumption;printf(消费者消费 %d 个苹果剩余苹果 %d个\n,consumption,apple_count);pthread_mutex_unlock(mutex);sleep(3);}return NULL; }int main(int argc, const char *argv[]) {pthread_t id_producer,id_consumer;pthread_create(id_producer,0,producer,0);pthread_create(id_consumer,0,consumer,0);pthread_join(id_producer,NULL);pthread_join(id_consumer,NULL);return 0; } 2运行效果
http://www.pierceye.com/news/288393/

相关文章:

  • 钦州建设局网站云南网站建设招商
  • 韩国风格网站php源码网站怎么放到服务器上
  • 网站调优yandex搜索引擎入口
  • 医院网站建设具体内容商丘网站制作电话
  • 别人做的网站直播网站
  • 足球梦网站建设的基本思路沧州做企业网站
  • 招标建设网站什么是微信wordpress
  • 建设银行网站连不上成都网站快照优化公司
  • 网站 永久关停 请示广州网站建设骏域网站
  • 个人建站模板外国网站翻墙怎么做
  • 保定网站设计制作公司有经验的中山网站建设
  • 免费网站建设那个好wordpress本地怎么上传服务器
  • 自己做的网站加载慢WordPress模板首页文件是啥
  • 教学网站建设网站建设岗位有哪些
  • 网站建设合同的验收表网页网站的区别是什么
  • 开福区网站建设中wordpress调用所有栏目
  • 网站建设的流程是什么意思青岛做网站公司
  • 什么网站有项目做中铁建设企业门户网
  • 网站域名商代理商安卓商店
  • 深圳中英文网站建设广州知名设计公司排名
  • 一个公司设计网站怎么做的蜜桃传奇免费网页版
  • 网络推广网站培训班有人用wordpress默认主题
  • 网站建设 后台南宁做网站方案
  • 在线制作插画网站网站建设有哪些公司
  • 合肥的网站建设剂屏自己可以做开奖网站吗
  • 官网设计比较好看的网站学校网站建设对教学的意义
  • 济南建站推荐企汇优见效付款毕设代做网站招聘
  • 泰然建设网站免费软件app下载大全正能量网站
  • 张掖市网站建设北京代理记账财务公司
  • 中铁建设集团网站网络公司手机网站