笔记2 linux多线程 读写锁
//read write lock
#include<stdio.h>
#include<unistd.h>
#include<pthread.h> struct test
{
char a[];
char b[];
char c[];
}yb = {"","",""}; static int j=; pthread_rwlock_t mutex_1; void Print1(struct test *arg)
{
pthread_rwlock_rdlock(&mutex_1);
printf("a=%s,b=%s,c=%s,d=%X,j=%d\n",arg->a,arg->b,arg->c,pthread_self(),j++);
sleep();
pthread_rwlock_unlock(&mutex_1);
pthread_exit((void *)j);
printf("Never Coming.\n");
} struct test *Print2(struct test *arg)
{
pthread_rwlock_wrlock(&mutex_1);
struct test *p = NULL;
p = arg;
memcpy(p->a,"fff",);
memcpy(p->b,"ggg",);
memcpy(p->c,"ttt",);
pthread_rwlock_unlock(&mutex_1);
pthread_exit((void *));
} int main()
{
pthread_t pid1,pid2,pid3,pid4;
void *set; pthread_rwlock_init(&mutex_1,NULL); pthread_create(&pid1,NULL,&Print1,&yb);
sleep();
pthread_create(&pid2,NULL,&Print2,&yb);
pthread_create(&pid3,NULL,&Print1,&yb);
sleep();
pthread_create(&pid4,NULL,&Print1,&yb); pthread_join(pid1,&set);
printf("pid1 exit coed %d\n",(int)set);
pthread_join(pid2,&set);
printf("pid2 exit coed %d\n",(int)set);
pthread_join(pid3,&set);
printf("pid3 exit coed %d\n",(int)set);
pthread_join(pid4,&set);
printf("pid4 exit coed %d\n",(int)set); pthread_rwlock_destroy(&mutex_1);
sleep();
return ;
}
笔记2 linux多线程 读写锁的更多相关文章
- linux中读写锁的rwlock介绍-nk_ysg-ChinaUnix博客
linux中读写锁的rwlock介绍-nk_ysg-ChinaUnix博客 linux中读写锁的rwlock介绍 2013-02-26 13:59:35 分类: C/C++ http://yaro ...
- 笔记整理--Linux多线程
Unix高级环境编程系列笔记 (2013/11/17 14:26:38) Unix高级环境编程系列笔记 出处信息 通过这篇文字,您将能够解答如下问题: 如何来标识一个线程? 如何创建一个新线程? 如何 ...
- java多线程-读写锁原理
Java5 在 java.util.concurrent 包中已经包含了读写锁.尽管如此,我们还是应该了解其实现背后的原理. 读/写锁的 Java 实现(Read / Write Lock Java ...
- 多线程 读写锁SRWLock
在<秒杀多线程第十一篇读者写者问题>文章中我们使用事件和一个记录读者个数的变量来解决读者写者问题.问题虽然得到了解决,但代码有点复杂.本篇将介绍一种新方法——读写锁SRWLock来解决这一 ...
- java多线程-读写锁
Java5 在 java.util.concurrent 包中已经包含了读写锁.尽管如此,我们还是应该了解其实现背后的原理. 读/写锁的 Java 实现(Read / Write Lock Java ...
- linux使用读写锁pthread_rwlock_t
转自:http://blog.csdn.net/onlyou930/article/details/6755593 使用读写锁 配置读写锁的属性之后,即可初始化读写锁.以下函数用于初始化或销毁读写锁. ...
- linux 一个读写锁的异常导致的故障
环境信息: WARNING: kernel version inconsistency between vmlinux and dumpfile KERNEL: vmlinux-47.90 DUMPF ...
- 笔记3 linux 多线程 条件变量+互斥锁
//cond lock #include<stdio.h> #include<unistd.h> #include<pthread.h> struct test { ...
- 笔记1 linux 多线程 互斥锁
//mutex lock #include<stdio.h> #include<unistd.h> #include<pthread.h> struct test ...
随机推荐
- SDWebImage4.0.0 源码解析
在开发iOS的客户端应用时,经常需要从服务器下载图片,虽然系统提供了下载工具:NSData.NSURLSession等等方法,但是考虑到图片下载过程中,需要考虑的因素比较多,比如:异步下载.图片缓存. ...
- 2017多校第9场 HDU 6161 Big binary tree 思维,类似字典树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6161 题意: 题目是给一棵完全二叉树,从上到下从左到右给每个节点标号,每个点有权值,初始权值为其标号, ...
- centos下安装jenkins
To use this repository, run the following command: sudo wget -O /etc/yum.repos.d/jenkins.repo https: ...
- JavaScript 学习笔记 - LocalStorage
前言 本文主要介绍本地存储的基本使用,以及它和 Cookie.SessionStorage 的区别. 简单回顾 Cookie 在 HTML5 之前,本地存储数据一般是通过 Cookie 来完成的.我们 ...
- 利用mvc filterconfig属性实现权限验证
好久没写过博客了,突然发现最后博客更新时间是2016年,感觉好长远 权限控制基本是所有cms系统或者进销存,或者几乎所有能和业务系统扯上关系的系统都要用上的一个模块,很多都想把这个模块独立出来,权限单 ...
- 再起航,我的学习笔记之JavaScript设计模式17(模板方法模式)
模板方法模式 由模板方法模式开始我们正式告别结构型设计模式,开始行为型设计模式的学习分享 行为型设计模式用于不同对象之间职责划分或算法抽象,行为型设计模式不仅仅涉及类和对象,还涉及类或对象之间的交流模 ...
- BeautifulSoup练习第一节
一.pip install beautilfulsoup4 二.主要使用html.parser这个python标准库 三.打印首页博客的时间.打印摘要 # coding:utf-8from bs4 i ...
- 深度学习框架-caffe安装-Mac OSX 10.12
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px ".PingFang SC"; color: #454545 } p.p2 ...
- 利用 FormData 对象和 Spring MVC 配合可以实现Ajax文件上载功能
Ajax文件上载 利用 FormData 对象和 Spring MVC 配合可以实现Ajax文件上载功能: 步骤 导入组件并准备静态脚本 <dependency> <groupId& ...
- BZOJ 3379: [Usaco2004 Open]Turning in Homework 交作业
Description 贝茜有C(1≤C≤1000)门科目的作业要上交,之后她要去坐巴士和奶牛同学回家. 每门科目的老师所在的教室排列在一条长为H(1≤H≤1000)的走廊上,他们只在课后接收 ...