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

服装网站建设策划书3000字软件开发包含网站开发吗

服装网站建设策划书3000字,软件开发包含网站开发吗,网络科技有限公司的简介,wordpress资源交易主题目录 互斥锁的概念和使用 线程通信-互斥 互斥锁的创建和销毁 申请锁-pthread_mutex_lock 释放锁-pthread_mutex_unlock 读写锁的概念和使用 死锁的避免 互斥锁的概念和使用 线程通信-互斥 临界资源 一次只允许一个任务#xff08;进程、线程#xff09;访问的共享资…目录 互斥锁的概念和使用  线程通信-互斥 互斥锁的创建和销毁 申请锁-pthread_mutex_lock 释放锁-pthread_mutex_unlock 读写锁的概念和使用 死锁的避免 互斥锁的概念和使用  线程通信-互斥 临界资源 一次只允许一个任务进程、线程访问的共享资源 概念 不能同时访问的资源比如写文件只能由一个线程写同时写会写乱。 比如外设打印机打印的时候只能由一个程序使用。 外设基本上都是不能共享的资源。 生活中比如卫生间同一时间只能由一个人使用。 临界区 访问临界资源的代码 互斥机制 mutex互斥锁任务访问临界资源前申请锁访问完后释放锁 互斥锁的创建和销毁 两种方法创建互斥锁静态方式和动态方式  动态方式  #include pthread.h int pthread_mutex_init(pthread_mutex_t *mutex,const pthread_mutexattr_t *attr); 成功时返回0失败时返回错误码mutex指向要初始化的互斥锁对象attr互斥锁属性NULL表示缺省属性man函数出现No manual entry for pthread_mutex_xxx解决方法apt-get install manpages-posix-dev 静态方式 pthread_mutex_t mutex PTHREAD_MUTEX_INITIALIZER; 锁的销毁: int pthread_mutex_destory(pthread_mutex_t *mutex) 在linux中互斥锁并不占用任何资源因此LinuxThreads中的pthread_mutex_destory()除了检查锁状态以外锁定状态则返回EBUSY没有其他动作。 申请锁-pthread_mutex_lock #include pthread.h int pthread_mutex_lock(pthread_mutex_t *mutex); int pthread_mutex_trylock(pthread_mutex_t *mutex); 成功时返回0失败时返回错误码mutex指向要初始化的互斥锁对象pthread_mutex_lock如果无法获得锁任务阻塞pthread_mutex_trylock如果无法获得锁返回EBUSY而不是挂起等待 释放锁-pthread_mutex_unlock #include pthread.h int pthread_mutex_unlock(pthread_mutex_t *mutex); 成功时返回0失败时返回错误码mutex指向要初始化的互斥锁对象 示例代码 #include stdio.h #include pthread.h #include unistd.h #include string.h FILE *fp; pthread_mutex_t mutex PTHREAD_MUTEX_INITIALIZER; //多个文件需要多个锁 void *func1(void *arg) {pthread_detach(pthread_self());printf(This is child thread1\n);char str[] I write func1 line\n;char c;int i 0;//pthread_mutex_t mutex1;while (1){pthread_mutex_lock(mutex);while(i strlen(str)){c str[i];fputc(c,fp);usleep(1);i;}pthread_mutex_unlock(mutex);i 0;usleep(1);}pthread_exit(func1 exit); } void *func2(void *arg) {pthread_detach(pthread_self());printf(This is child thread2\n);char str[] You read func1 thread\n;char c;int i 0;//pthread_mutex_t mutex2;while (1){pthread_mutex_lock(mutex);while(i strlen(str)){c str[i];fputc(c,fp);usleep(1);i;}pthread_mutex_unlock(mutex);i 0;usleep(1);}pthread_exit(func2 exit); } int main() { pthread_t tid1,tid2;void *retv;int i; fp fopen(1.txt,a);if(fp NULL){perror(fopen);return 0;}pthread_create(tid1,NULL,func1,NULL);pthread_create(tid2,NULL,func2,NULL);while(1){sleep(1);} }运行结果 读写锁的概念和使用 必要性提高线程执行效率 特性 写者写者使用写锁如果当前没有读者也没有其他写者写者立即获得写锁否则写者将等待直到没有读者和写者。读者读者使用读锁如果当前没有写者读者立即获得读锁否则读者等待直到没有写者。 注意 同一时刻只有一个线程可以获得写锁同一时刻可以有多个线程获得读锁。读写锁出于写锁状态时所有试图对读写锁加锁的线程不管是读者试图加读锁还是写者试图加写锁都会被阻塞。读写锁处于读锁状态时有写者试图加写锁时之后的其他线程的读锁请求会被阻塞以避免写者长时间的不写锁。 初始化一个读写锁        pthread_rwlock_init读锁定读写锁                pthread_rwlock_rdlock非阻塞读锁定                pthread_rwlock_tryrdlock写锁定读写锁                pthread_rwlock_wrlock非阻塞写锁定                pthread_rwlock_trywrlock解锁读写锁                    pthread_rwlock_unlock释放读写锁                    pthread_rwlock_destroy 示例代码 #include pthread.h #include stdio.h #include unistd.h #include string.hpthread_rwlock_t rwlock;FILE *fp; void * read_func(void *arg){pthread_detach(pthread_self());printf(read thread\n);char buf[32]{0};while(1){//rewind(fp);pthread_rwlock_rdlock(rwlock);while(fgets(buf,32,fp)!NULL){printf(%d,rd%s\n,(int)arg,buf);usleep(1000);}pthread_rwlock_unlock(rwlock);sleep(1);}}void *func2(void *arg){pthread_detach(pthread_self());printf(This func2 thread\n);char str[]I write func2 line\n;char c;int i0;while(1){pthread_rwlock_wrlock(rwlock);while(istrlen(str)){c str[i];fputc(c,fp);usleep(1);i;}pthread_rwlock_unlock(rwlock);i0;usleep(1);}pthread_exit(func2 exit);}void *func(void *arg){pthread_detach(pthread_self());printf(This is func1 thread\n);char str[]You read func1 thread\n;char c;int i0;while(1){pthread_rwlock_wrlock(rwlock);while(istrlen(str)){c str[i];fputc(c,fp);i;usleep(1);}pthread_rwlock_unlock(rwlock);i0;usleep(1);}pthread_exit(func1 exit); }int main(){pthread_t tid1,tid2,tid3,tid4;void *retv;int i;fp fopen(1.txt,a);if(fpNULL){perror(fopen);return 0;}pthread_rwlock_init(rwlock,NULL);pthread_create(tid1,NULL,read_func,1);pthread_create(tid2,NULL,read_func,2);pthread_create(tid3,NULL,func,NULL);pthread_create(tid4,NULL,func2,NULL);while(1){ sleep(1);} }死锁的避免 锁越少越好最好使用一把锁调整好锁的顺序使锁进行错位 示例代码 #include stdio.h #include pthread.h #include unistd.h #include string.h FILE *fp; pthread_mutex_t mutex PTHREAD_MUTEX_INITIALIZER; //多个文件需要多个锁 pthread_mutex_t mutex2 PTHREAD_MUTEX_INITIALIZER; //多个文件需要多个锁void *func1(void *arg) {pthread_detach(pthread_self());printf(This is child thread1\n);char str[] I write func1 line\n;char c;int i 0;//pthread_mutex_t mutex1;while (1){pthread_mutex_lock(mutex2);printf(%d,I get lock2\n,(int)arg);sleep(1);pthread_mutex_lock(mutex);printf(%d,I get 2 locks\n,(int)arg);pthread_mutex_unlock(mutex);pthread_mutex_unlock(mutex2);sleep(10);}pthread_exit(func1 exit); } void *func2(void *arg) {pthread_detach(pthread_self());printf(This is child thread2\n);char str[] You read func1 thread\n;char c;int i 0;//pthread_mutex_t mutex2;while (1){pthread_mutex_lock(mutex);printf(%d,I get lock1\n,(int)arg);sleep(1);pthread_mutex_lock(mutex2);printf(%d,I get 2 locks\n,(int)arg);pthread_mutex_unlock(mutex2);pthread_mutex_unlock(mutex);usleep(10);}pthread_exit(func2 exit); } int main() { pthread_t tid1,tid2;void *retv;int i; fp fopen(1.txt,a);if(fp NULL){perror(fopen);return 0;}pthread_create(tid1,NULL,func1,1);sleep(5);pthread_create(tid2,NULL,func2,2);while(1){sleep(1);} }运行结果
http://www.pierceye.com/news/785526/

相关文章:

  • 免费网站的建设绵阳网站建设制作
  • 学生处网站建设招标公告网站包括哪些主要内容
  • 成都门户网站建设多少钱聚合广告联盟
  • 坦克大战网站开发课程设计报告软文营销的本质
  • 美食网站开发网站登录验证码是怎么做的
  • 电子商务网站排名辽宁省建设工程信息网业绩公示
  • 天津建设科技杂志的官方网站wordpress cnzz插件
  • 滨州建设网站太原网站建设优化
  • 记事本做网站怎么改字体包装设计模板设计素材
  • 下载软件的网站推荐thinkphp和wordpress
  • 青海省城乡和住房建设厅网站合肥小吃培训网页设计
  • 财经门户网站建设django校园网站开发
  • 泉州网站建设报价广东建设厅网站
  • 建设网站的源代码的所有权wordpress网站打开慢
  • 印度外贸网站有哪些家居小程序源码下载
  • 上海网站建设中心pc官方网站
  • 深圳企业网站制作公司查询西安网站设计哪家好
  • 大埔做网站手机qq邮箱发布了wordpress
  • 寻找南昌网站设计单位网站建设 中企动力医院
  • 中间商可以做网站吗平面广告设计师的工作内容
  • 网站建设用户分析做网站有什么软件
  • 洛阳网站建设启辰网络wordpress怎么破解查看
  • 长沙市网站设计公司厦门建设网站建站
  • 网站做链轮会被惩罚吗网站开发系统
  • 一般做企业网站需要什么资料WordPress情侣博客模板
  • 网站开发教程公司哪些官网用wordpress
  • redis网站开发教程创建app软件
  • 企业网站新闻wp怎么做合肥环保公司网站建设
  • 怎么仿一个复杂的网站wordpress描述怎么改
  • php 如何用op浏览器开发手机网站app开发制作哪种快