多线程
文章平均质量分 89
weixin_panda
这个作者很懒,什么都没留下…
展开
-
Linux C++多线程同步
文章目录一.互斥锁二.条件变量三.读写锁四.信号量 背景问题:在特定的应用场景下,多线程不进行同步会造成什么问题? 通过多线程模拟多窗口售票为例: #include<iostream> #include<pthread.h> #include<unistd.h> using namespace std; int ticket_sum = 20; void * sell_ticket(void * arg) { for(int i=0; i<20; i+原创 2021-01-25 15:19:11 · 151 阅读 · 0 评论 -
Linux C++ 多线程编程实例
Linux系统下的多线程遵循POSIX线程接口,称为 pthread。编写Linux下的多线程程序,需要使用头文件pthread.h,连接时需要使用库libpthread.a。顺便说一下,Linux 下pthread的实现是通过系统调用clone()来实现的。clone()是 Linux所特有的系统调用,它的使用方式类似fork。 1、线程创建 pthread_create int pthread_create(pthread_t *restrict tidp,const pthread_attr_t *r原创 2021-01-14 17:12:40 · 443 阅读 · 0 评论