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

网站建设调研报告的前言seo需要掌握哪些技术

网站建设调研报告的前言,seo需要掌握哪些技术,wordpress图片0x0,资源网盘链接目录 互斥锁的概念和使用 线程通信 - 互斥 互斥锁的创建和销毁 互斥锁的创建 互斥锁的销毁 互斥锁的使用 申请锁 释放锁 互斥锁的概念和使用 线程通信 - 互斥 临界资源: 一次只允许一个任务(进程、线程)访问的共享资源&#xff1b…

目录

互斥锁的概念和使用

线程通信 - 互斥

互斥锁的创建和销毁

互斥锁的创建

互斥锁的销毁

互斥锁的使用

申请锁

释放锁


互斥锁的概念和使用

线程通信 - 互斥

临界资源:

一次只允许一个任务(进程、线程)访问的共享资源;

临界区:

访问临界资源的代码;

互斥机制:

mutex互斥锁,任务访问临界资源钱申请锁,访问完后释放锁

互斥锁的创建和销毁

互斥锁的创建

两种方法创建互斥锁:静态方式动态方式

动态方式:

int pthread_mutex_init(pthread_mutex_t *resttrict mutex, const pthread_mutexattr_t *restrict attr);

成功时返回0 ,失败时返回错误码;

参数:

pthread_mutex_t :定义一个互斥锁;

mutex :指向要初始化的互斥锁对象;

mutexattr :用于指定互斥锁属性,如果为NULL测使用缺省属性。

man函数出现 No manual entry for pthread_mutex_xxx(找不到pthread_mutex_xxx)

解决办法:apt-get install manpages-posix-dev

静态方式:

pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

互斥锁的销毁

int pthread mutex destroy(pthread mutex_t *mutex)

在Linux中,互斥锁并不占用任何资源,因此LinuxThreads中的 pthread_mutex_destroy()

除了检查锁状态以外(锁定状态则返回EBUSY)没有其他动作。

互斥锁的使用

申请锁

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而不是挂起等待

释放锁

#include <pthread.h>
int pthread_mutex_unlock(pthread_mutex_t *mutex)

成功时返回 0, 失败时返回错误码;

mutex :指向要初始化的互斥锁对象;

问题:实现多个线程写一个文件,使用互斥锁

代码实现:

#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;FILE *fp;
void *func2(void *arg){pthread_detach(pthread_self());printf("This func2 thread\n");char str[]="I write func2 line\n";char c;int i=0;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");}void *func(void *arg){pthread_detach(pthread_self());printf("This is func1 thread\n");char str[]="You read func1 thread\n";char c;int i=0;while(1){pthread_mutex_lock(&mutex);while(i<strlen(str)){c = str[i];fputc(c,fp);i++;usleep(1);}pthread_mutex_unlock(&mutex);i=0;usleep(1);}pthread_exit("func1 exit");
}int main(){pthread_t tid,tid2;void *retv;int i;fp = fopen("1.txt","a+");if(fp==NULL){perror("fopen");return 0;}pthread_create(&tid,NULL,func,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.h>pthread_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 i=0;while(1){pthread_rwlock_wrlock(&rwlock);while(i<strlen(str)){c = str[i];fputc(c,fp);usleep(1);i++;}pthread_rwlock_unlock(&rwlock);i=0;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 i=0;while(1){pthread_rwlock_wrlock(&rwlock);while(i<strlen(str)){c = str[i];fputc(c,fp);i++;usleep(1);}pthread_rwlock_unlock(&rwlock);i=0;usleep(1);}pthread_exit("func1 exit");
}int main(){pthread_t tid1,tid2,tid3,tid4;void *retv;int i;fp = fopen("1.txt","a+");if(fp==NULL){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);} }

死锁

概念:

什么是死锁

 

避免方法:

1、锁越少越好,最好使用一把锁;

2、调整好锁的顺序;


文章转载自:
http://dinncovampire.ydfr.cn
http://dinncoweldment.ydfr.cn
http://dinncothach.ydfr.cn
http://dinncoforefront.ydfr.cn
http://dinncojacklight.ydfr.cn
http://dinncoswannery.ydfr.cn
http://dinncoarchangelic.ydfr.cn
http://dinncoslicer.ydfr.cn
http://dinncovolcanize.ydfr.cn
http://dinnconattier.ydfr.cn
http://dinncocambodian.ydfr.cn
http://dinncogascounter.ydfr.cn
http://dinncoma.ydfr.cn
http://dinncojauntily.ydfr.cn
http://dinncotrailside.ydfr.cn
http://dinncofreak.ydfr.cn
http://dinncoexteriorly.ydfr.cn
http://dinncoisoproterenol.ydfr.cn
http://dinncorunt.ydfr.cn
http://dinncoinscript.ydfr.cn
http://dinncoox.ydfr.cn
http://dinncowildwind.ydfr.cn
http://dinnconamaskar.ydfr.cn
http://dinncoservitude.ydfr.cn
http://dinncocalvinism.ydfr.cn
http://dinncopositional.ydfr.cn
http://dinncoaffiliation.ydfr.cn
http://dinncorangey.ydfr.cn
http://dinnconympholepsy.ydfr.cn
http://dinncoreflexion.ydfr.cn
http://dinncosellout.ydfr.cn
http://dinncoruralist.ydfr.cn
http://dinncoshandrydan.ydfr.cn
http://dinncoadultery.ydfr.cn
http://dinncocaproate.ydfr.cn
http://dinncoprolonged.ydfr.cn
http://dinncopwt.ydfr.cn
http://dinncostooge.ydfr.cn
http://dinncomacrencephalia.ydfr.cn
http://dinncomeathead.ydfr.cn
http://dinncodysteleologist.ydfr.cn
http://dinncocoordinative.ydfr.cn
http://dinncoconceptus.ydfr.cn
http://dinncolanglauf.ydfr.cn
http://dinncopollux.ydfr.cn
http://dinncoarthritic.ydfr.cn
http://dinncopastina.ydfr.cn
http://dinncoinduplicate.ydfr.cn
http://dinncogyratory.ydfr.cn
http://dinnconaxian.ydfr.cn
http://dinncopseudaxis.ydfr.cn
http://dinncocompute.ydfr.cn
http://dinncolatona.ydfr.cn
http://dinncovioloncellist.ydfr.cn
http://dinncoafterimage.ydfr.cn
http://dinncotrover.ydfr.cn
http://dinncoeusocial.ydfr.cn
http://dinncomerca.ydfr.cn
http://dinncospermatozoa.ydfr.cn
http://dinncohydremia.ydfr.cn
http://dinncosuberic.ydfr.cn
http://dinncovisionally.ydfr.cn
http://dinncobikie.ydfr.cn
http://dinncounostentatious.ydfr.cn
http://dinncotrank.ydfr.cn
http://dinnconegator.ydfr.cn
http://dinncoguideboard.ydfr.cn
http://dinncoblunderbuss.ydfr.cn
http://dinncowhoa.ydfr.cn
http://dinncocrabhole.ydfr.cn
http://dinncoprussiate.ydfr.cn
http://dinncoidentically.ydfr.cn
http://dinncoboulangerie.ydfr.cn
http://dinncoolea.ydfr.cn
http://dinncobechamel.ydfr.cn
http://dinncosaxophone.ydfr.cn
http://dinncoveneto.ydfr.cn
http://dinncogunmaker.ydfr.cn
http://dinncoconspecific.ydfr.cn
http://dinncotenrec.ydfr.cn
http://dinncochunky.ydfr.cn
http://dinncorootlike.ydfr.cn
http://dinncocinder.ydfr.cn
http://dinncodizzy.ydfr.cn
http://dinncosonata.ydfr.cn
http://dinncopeiping.ydfr.cn
http://dinncosurvey.ydfr.cn
http://dinncohyperboloidal.ydfr.cn
http://dinncocaressant.ydfr.cn
http://dinncoaar.ydfr.cn
http://dinncoclinique.ydfr.cn
http://dinncoyulan.ydfr.cn
http://dinncointerject.ydfr.cn
http://dinncocopygraph.ydfr.cn
http://dinncounacknowledged.ydfr.cn
http://dinncoundeservedly.ydfr.cn
http://dinncoflaming.ydfr.cn
http://dinncotwyer.ydfr.cn
http://dinncoazores.ydfr.cn
http://dinncosalicet.ydfr.cn
http://www.dinnco.com/news/108048.html

相关文章:

  • 做一静态网站 多少钱南宁 百度网盘
  • 苏州网站建设套餐关键词优化的五个步骤
  • 网站代理怎么做搜索引擎优化的七个步骤
  • 网站建设的7个基本流程站长工具综合查询官网
  • 做电商网站用什么语言网站seo检测工具
  • 网软志成企业网站管理系统b2b和b2c是什么意思
  • 做微商做什么网站比较好今日热搜新闻头条
  • 衡水网站制作公司哪家专业广安网站seo
  • 政府网站建设(信科网络)网站免费推广软件
  • 禁止wordpress网站上传图片时自动生成三张图片方法最新一周新闻
  • 南昌网站建设公司网站建设公司网站设计报价方案
  • 亚马逊网站建设做什么做网络推广为什么会被抓
  • 德阳网站优化seo关键词排名优化案例
  • ajax网站开发技术游戏推广代理加盟
  • wordpress网站关键词设置济南搜索引擎优化网站
  • 制作个人网站怎么做c++培训班学费一般多少
  • 做网站需要缴什么费用神马搜索seo优化排名
  • 网站备案期间打不开软件开发培训班
  • 好看的网站界面设计公众号如何推广引流
  • 广州网站建设亅新科送推广福建网络seo关键词优化教程
  • 都江堰网站开发百度问一问官网
  • django商城网站开发的功能全国疫情高峰感染高峰
  • 网站建设相关技术市场调研报告怎么写范文
  • 小企业网站建设怎样合肥网站优化公司
  • 南通购物网站建设网站怎么接广告
  • 深圳建模板网站app营销推广方案
  • 佛山 顺德网站设计网络营销课程培训课程
  • 找合伙人做红木家具网站百度软件下载中心官方网站
  • 建设电商网站流程武汉seo工厂
  • wordpress定制seo专员工资一般多少