读写锁的分配规则如下:1. 只要没有线程持有某个指定的读写锁用于写,那么任意数目的线程可以持有该读写锁用于读;2. 仅当没有线程持有某个指定的读写锁用于读或者用于写,才能分配读写锁用于写。这样的访问方式也称为共享-独占上锁(shared-exclusion)那么我想到了这样一个场景:线程A要写数据,...
分类:
系统相关 时间:
2015-07-07 12:55:00
阅读次数:
137
Posix semaphore有名信号量/* sem_open - initialize and open a named semaphore */#include /* For O_* constants */#include /* For mode cons...
分类:
系统相关 时间:
2015-07-07 12:46:03
阅读次数:
188
进程间的互斥,我们可以让这些进程共享某个内存区(mmap实现),然后在该共享内存区中使用某种类型的同步变量但是,fcntl记录上锁往往更容易使用。#include #include int fcntl(int fd, int cmd, ... /* struct flock *arg */ );st...
分类:
系统相关 时间:
2015-07-07 12:27:55
阅读次数:
137
1. Posix 消息队列/* mq_open - open a message queue */#include /* For O_* constants */#include /* For mode constants */#include mqd_t mq...
分类:
系统相关 时间:
2015-07-01 17:31:34
阅读次数:
167
linux应用开发-无名管道编程
一 linux进程间通信(ipc)
1 UNIX进程间通信
2 基于System V的通信
3 POSIX通信
二 七种通信方式
1 管道
一个进程在管道的尾部写入数据,另一个进程从管道的头部
读出数据。管道包括无名管道和有名管道两种,前者只能用
于父进程和子进程间的通信,后者可用于运行于同一系统中
的任意两个进程间的通信。
...
分类:
系统相关 时间:
2015-05-01 13:24:32
阅读次数:
205
信号量(也叫信号灯)是一种用于提供不同进程间或一个给定进程的不同线程间同步手段的原语。信号量是进程/线程同步的一种方式,有时候我们需要保护一段代码,使它每次只能被一个执行进程/线程运行,这种工作就需要一个二进制开关;有时候需要限制一段代码可以被多少个进程/线程执行,这就需要用到关于计数信号量。信号量...
分类:
系统相关 时间:
2015-04-17 17:20:07
阅读次数:
207
SystemV共享内存机制:shmgetshmatshmdtshmctl原理及实现:systemVIPC机制下的共享内存本质是一段特殊的内存区域,进程间需要共享的数据被放在该共享内存区域中,所有需要访问该共享区域的进程都要把该共享区域映射到本进程的地址空间中去。这样一个使用共享内存的进程可以将信息写...
分类:
系统相关 时间:
2015-04-17 15:26:58
阅读次数:
222
http://www.ibm.com/developerworks/cn/linux/l-ipc/part2/index2.htmlhttp://bbs.chinaunix.net/forum.php?mod=viewthread&tid=3628569http://www.uml.org.cn/e...
分类:
系统相关 时间:
2015-03-07 11:28:43
阅读次数:
205
1. 创建/获取一个共享内存#include
#include /* For mode constants */
#include /* For O_* constants */
int shm_open(const char *name, int oflag, mode_t mode);参数: name: 共享内存名字; oflag: 与open...
分类:
系统相关 时间:
2015-02-19 16:23:17
阅读次数:
219
信号量API#include
#include
#include
int semget(key_t key, int nsems, int semflg);
int semctl(int semid, int semnum, int cmd, ...);
int semop(int semid, struct sembuf *sops, unsigned nsops);semgetint s...
分类:
系统相关 时间:
2015-02-19 16:20:27
阅读次数:
283