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

成都设计院排行seo中文含义是什么

成都设计院排行,seo中文含义是什么,探马scrm,网站数据库密码修改了要怎么做要求定义一个全局变量 char buf[] "1234567",创建两个线程,不考虑退出条件,另: A线程循环打印buf字符串,B线程循环倒置buf字符串,即buf中本来存储1234567,倒置后buf中存储7654321. 不…

        要求定义一个全局变量 char buf[] = "1234567",创建两个线程,不考虑退出条件,另:

  1. A线程循环打印buf字符串,
  2. B线程循环倒置buf字符串,即buf中本来存储1234567,倒置后buf中存储7654321. 不打印!!
  3. 倒置不允许使用辅助数组。
  4. 要求A线程打印出来的结果只能为 1234567 或者 7654321 不允许出现7634521 7234567
  5. 不允许使用sleep函数

方法一:使用flag将其分离

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <head.h>
#include <fcntl.h>
#include <unistd.h>
#include <pthread.h>char buf[]="1234567";
int flag= 0 ;void* callback_1(void* arg)//打印
{while(1){if(0 == flag){printf("%s\n",buf);flag=1;}}pthread_exit(NULL);
}void* callback_2(void* arg)//逆置 不打印
{char t=0;while(1){if(1 == flag){for(int i=0;i<strlen(buf)/2;i++){t=buf[i];buf[i] = buf[strlen(buf)-1-i];buf[strlen(buf)-1-i] = t;}flag=0;}}pthread_exit(NULL);
}int main(int argc, const char *argv[])
{pthread_t tid_1,tid_2;if(pthread_create(&tid_1,NULL,callback_1,NULL)!=0){fprintf(stderr,"pthread_create failed __%d__\n",__LINE__);return -1;}pthread_detach(tid_1);  //分离线程1if(pthread_create(&tid_2,NULL,callback_2,NULL)!=0){fprintf(stderr,"pthread_create failed __%d__\n",__LINE__);return -1;}pthread_join(tid_2,NULL);printf("主线程准备退出");return 0;
}

 方法二:使用互斥锁

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <head.h>
#include <fcntl.h>
#include <unistd.h>
#include <pthread.h>
//临界资源
char buf[]="1234567";//互斥锁
pthread_mutex_t mutex;void* callback_1(void* arg)//打印
{while(1){/***********临界区**************///上锁pthread_mutex_lock(&mutex);printf("%s\n",buf);//解锁pthread_mutex_unlock(&mutex);/***********临界区**************/}pthread_exit(NULL);
}void* callback_2(void* arg)//逆置 不打印
{char t=0;while(1){/***********临界区**************///上锁pthread_mutex_lock(&mutex);for(int i=0;i<strlen(buf)/2;i++){t=buf[i];buf[i] = buf[strlen(buf)-1-i];buf[strlen(buf)-1-i] = t;}//解锁pthread_mutex_unlock(&mutex);/***********临界区**************/}pthread_exit(NULL);
}int main(int argc, const char *argv[])
{//申请一个互斥锁pthread_mutex_init(&mutex,NULL);pthread_t tid_1,tid_2;if(pthread_create(&tid_1,NULL,callback_1,NULL)!=0){fprintf(stderr,"pthread_create failed __%d__\n",__LINE__);return -1;}pthread_detach(tid_1);  //分离线程1if(pthread_create(&tid_2,NULL,callback_2,NULL)!=0){fprintf(stderr,"pthread_create failed __%d__\n",__LINE__);return -1;}pthread_join(tid_2,NULL);  //阻塞等待线程2退出//销毁互斥锁pthread_mutex_destroy(&mutex);return 0;
}

http://www.hkea.cn/news/134460/

相关文章:

  • 注册安全工程师管理系统网奇seo赚钱培训
  • 武汉市住房和城乡建设厅官方网站生猪价格今日猪价
  • 住房和城乡建设部网站诚信评价搜索引擎优化人员优化
  • 网站制作 太原网络营销专业课程
  • 做网站去哪个公司网络营销策划书的结构
  • 个人无网站怎样做cps广告深圳全网推广公司
  • 中国人可以做的c2c网站上海网站排名推广
  • 网站建设目标定位公司员工培训方案
  • 美工培训班学百度自然搜索排名优化
  • 网站建设自学多长时间搜索引擎营销的过程
  • 做cpa的网站源码seo的外链平台有哪些
  • 那个网站做外贸最好成都网站建设方案外包
  • 企业网站建设效益分析联合早报 即时消息
  • html5网页成品代码自媒体seo优化
  • 门户网站建设招投标网络seo啥意思
  • 游戏币销售网站建设百度热搜seo
  • 线上投票链接怎么做厦门搜索引擎优化
  • 网页设计课程主要内容seo学校
  • php 深圳 电子商务网站开发seo优化好做吗
  • 网站建设开发技术天津济南网站设计
  • 信息公开网站建设网店推广分为哪几种类型
  • 南皮网站建设价格seo搜索引擎优化方式
  • 网上购物系统的设计与实现论文长沙seo优化公司
  • 风景旅游网页制作素材seo推广灰色词
  • 网站制作网站建设网页设计页面
  • 网站开发兼容极速字体颜色推荐seo平台优化服务
  • wordpress建站流量齐三seo顾问
  • 怎么看一个网站做没做竞价公司网站怎么建立
  • seo神马网站推广器怎么做神马搜索排名seo
  • 桂林漓江景区网站优化推广排名