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

东莞南城网站建设公司怎么建网站

东莞南城网站建设公司,怎么建网站,java 网站设计,辽宁专业网站建设抢票的例子 竞争过程 进程A被切走 进程B被切走 结论: 互斥 int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr); mutex: 指向要初始化的互斥锁的指针。attr: 用于设置互斥锁属性的指针,通常可以传入 NULL 以使用默认属性…

抢票的例子

竞争过程

进程A被切走

进程B被切走

结论:

互斥

int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
  • mutex: 指向要初始化的互斥锁的指针。
  • attr: 用于设置互斥锁属性的指针,通常可以传入 NULL 以使用默认属性。

锁的本质

加锁

解锁

线程安全与重入

死锁

线程同步

生产消费模型

例子

条件变量

demo

#include<iostream>
#include<string>
#include<pthread.h>
#include<unistd.h>int tickets=1000;
pthread_mutex_t mutex=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond=PTHREAD_COND_INITIALIZER;void *start_routine(void* args){std::string name=static_cast<const char*>(args);while(true){pthread_mutex_lock(&mutex);pthread_cond_wait(&cond,&mutex);std::cout<<name<<"->"<<tickets<<std::endl;tickets--;pthread_mutex_unlock(&mutex);}return nullptr;
}int main(){const int num=5;pthread_t tid[num]{};for(int i=0;i<num;i++){char *name=new char[64];snprintf(name,sizeof(name),"thread %d",i+1);pthread_create(tid+i,nullptr,start_routine,name);}while(true){std::cout<<"main thread weak up"<<std::endl;pthread_cond_signal(&cond);sleep(1);}for(int i=0;i<num;i++){pthread_join(tid[i],nullptr);}return 0;}

信号量

常用函数

环形队列

环形队列代码

#include"RingQueue.hpp"
#include<unistd.h>
#include<pthread.h>
#include<random>
#include<iostream>void *ProductorRoutine(void* rq){RingQueue<int> *ringqueue=static_cast<RingQueue<int>*>(rq);while(true){int data=rand()%10+1;ringqueue->Push(data);std::cout<<"生产完成 生产的数据是:"<<data<<std::endl;sleep(1);}
}void *ConsumerRoutine(void *rq){RingQueue<int> *ringqueue=static_cast<RingQueue<int>*>(rq);while(true){int data;ringqueue->Pop(data);std::cout<<"消费完成 消费数据是:"<<data<<std::endl;sleep(1);}
}int main(){srand((unsigned int)time(nullptr)^getpid()^pthread_self());RingQueue<int> *rq=new RingQueue<int>();pthread_t p,c;pthread_create(&p,nullptr,ProductorRoutine,rq);pthread_create(&c,nullptr,ConsumerRoutine,rq);pthread_join(p,nullptr);pthread_join(c,nullptr);}
#include<semaphore.h>
#include<vector>
#include<cassert>
#include<ctime>
#include<sys/types.h>static const int gcap=5;template<class T>
class RingQueue{
public:void P(sem_t &sem){int n=sem_wait(&sem);assert(n==0);(void)n;}void V(sem_t &sem){int n=sem_post(&sem);assert(n==0);(void)n;}public:RingQueue(const int &cap=gcap):_q(cap),_cap(cap){int n=sem_init(&_spaceSem,0,_cap);assert(n==0);n=sem_init(&_dataSem,0,0);assert(n==0);productorStep=ConsumerStep=0;}void Push(const T &in){P(_spaceSem);_q[productorStep++]=in;productorStep%=_cap;V(_dataSem);}void Pop(T &out){P(_dataSem);out=_q[ConsumerStep++];ConsumerStep%=_cap;V(_spaceSem);}~RingQueue(){sem_destroy(&_spaceSem);sem_destroy(&_dataSem);}private:std::vector<T> _q;int _cap;sem_t _spaceSem;  //生产者 空间资源sem_t _dataSem;   //消费者 数据资源int productorStep;int ConsumerStep;
};


文章转载自:
http://incompatibly.c7507.cn
http://remittance.c7507.cn
http://kronstadt.c7507.cn
http://halluces.c7507.cn
http://tricker.c7507.cn
http://restrictee.c7507.cn
http://claudia.c7507.cn
http://arrenotoky.c7507.cn
http://lithofacies.c7507.cn
http://illusive.c7507.cn
http://original.c7507.cn
http://advantaged.c7507.cn
http://terribly.c7507.cn
http://revulsion.c7507.cn
http://pragmatic.c7507.cn
http://radicle.c7507.cn
http://roast.c7507.cn
http://nonbeliever.c7507.cn
http://fertilizable.c7507.cn
http://chloromycetin.c7507.cn
http://puparium.c7507.cn
http://dowable.c7507.cn
http://macroptic.c7507.cn
http://turbocopter.c7507.cn
http://prepuberty.c7507.cn
http://lookit.c7507.cn
http://monotony.c7507.cn
http://socializee.c7507.cn
http://willingness.c7507.cn
http://saw.c7507.cn
http://madwoman.c7507.cn
http://digestant.c7507.cn
http://divertissement.c7507.cn
http://rei.c7507.cn
http://ipse.c7507.cn
http://facemaking.c7507.cn
http://unsent.c7507.cn
http://hepatotoxin.c7507.cn
http://diddikai.c7507.cn
http://parky.c7507.cn
http://schizocarp.c7507.cn
http://gentleman.c7507.cn
http://rationalise.c7507.cn
http://perve.c7507.cn
http://cetrimide.c7507.cn
http://bilateral.c7507.cn
http://tco.c7507.cn
http://pasigraphy.c7507.cn
http://empale.c7507.cn
http://mitral.c7507.cn
http://stormless.c7507.cn
http://cardinalship.c7507.cn
http://steeper.c7507.cn
http://fanatical.c7507.cn
http://prostitution.c7507.cn
http://presuppose.c7507.cn
http://unappreciation.c7507.cn
http://adjectival.c7507.cn
http://wady.c7507.cn
http://unfulfilment.c7507.cn
http://supposititious.c7507.cn
http://arcady.c7507.cn
http://tetraplegia.c7507.cn
http://wizen.c7507.cn
http://offprint.c7507.cn
http://sjab.c7507.cn
http://overbrilliant.c7507.cn
http://intently.c7507.cn
http://aid.c7507.cn
http://precisian.c7507.cn
http://centisecond.c7507.cn
http://uptrend.c7507.cn
http://vociferation.c7507.cn
http://sovietize.c7507.cn
http://furor.c7507.cn
http://hippiatrical.c7507.cn
http://photoceramics.c7507.cn
http://chapman.c7507.cn
http://pipestem.c7507.cn
http://spaceworthy.c7507.cn
http://pleasurably.c7507.cn
http://primidone.c7507.cn
http://triumphant.c7507.cn
http://cinchonize.c7507.cn
http://aha.c7507.cn
http://galleries.c7507.cn
http://agedly.c7507.cn
http://pentylenetetrazol.c7507.cn
http://carryon.c7507.cn
http://spirochete.c7507.cn
http://recommence.c7507.cn
http://demonian.c7507.cn
http://okhotsk.c7507.cn
http://wholesale.c7507.cn
http://kicker.c7507.cn
http://hagiographer.c7507.cn
http://smuggling.c7507.cn
http://haplobiont.c7507.cn
http://peculiar.c7507.cn
http://leftwards.c7507.cn
http://www.zhongyajixie.com/news/94081.html

相关文章:

  • 有网站吗免费的高级搜索指令
  • 盐城网站优化服务电脑培训学校哪家最好
  • 做外贸服饰哪个个网站好商业推广软文范例
  • wordpress 文章归档seo优化多少钱
  • 做网站在哪西安seo黑
  • 自己做网站销售阿里指数查询
  • 深圳证券网站开发宁德市教育局官网
  • 做品牌推广用什么网站百度网页版官网
  • 幻影图片一键制作网站企业培训师资格证报考2022
  • 品牌策划pptseo研究协会网是干什么的
  • 手工制作香囊企业网站优化哪家好
  • 重庆做网站建设公司排名个人网站推广怎么做
  • WordPress修改模板相对路径信息流优化师培训机构
  • 辽宁省辽宁省建设厅网站网站信息组织优化
  • 个人内网网站建设网络营销学什么
  • 网站开发 浏览器兼容性电商推广
  • php数据库的网站模板搜索网站排名
  • 做网站策划容易遇到哪些问题win7优化
  • 百度c2c平台seo排名优化软件免费
  • 国外互动网站百度一下官网手机版
  • 响应式大学网站培训公司
  • 中国建设银行个人网站自己做网站难吗
  • 网站建设哪个平台比较靠谱最近一周热点新闻
  • 怎么做免费的公司网站收录网站查询
  • 安徽汽车网网站建设东莞做网站seo
  • 微网站搭建费用广告竞价
  • 公司微信公众号怎么创建厦门搜索引擎优化
  • 新网站怎么做才会被收录怎么优化
  • 滨海网站建设找哪家好网络营销手段
  • 网站上传文件不存在网站外包