public class SomeContainer { private Set<element> elements; private ReadWriteLock globalLock; private Lock readLock; private Lock writeLock; SomeContainer() { elements = new HashSet<element>(); globalLock = new ReentrantReadWriteLock(); readLock = globalLock.readLock(); writeLock = globalLock.writeLock(); } public void addElement(Element elem) { writeLock.lock(); try { elements.add(elem); } finally { writeLock.unlock(); } } public void processElements(ElementProcessor processor) { readLock.lock(); try { Iterator<element> iter = elements.iterator(); while(iter.hasNext()) { Element element = iter.next(); processor.processElement(element); } finally { readLock.unlock(); } // ... }interface ElementProcessor { void processElement(Element element);}
So, in the example above, the first line in processElements
will let everybody play at once so long as the write lock is not held. Then, when the write lock is requested, the requesting thread will be made to wait until all existing readers are done (no further readers will be let in), and then the writer thread may begin.
http://www.javalobby.com/java/forums/t45090.html
分享到:
相关推荐
在linux下按照windows的slim read/write lock算法实现的读写锁源码。
linux下实现高性能读写锁(read/write lock) 附带makefile,工程模板
Read/write lock synchronization APIs Signals APIs What are Pthreads? Primitive data types for Pthreads Feature test macros for Pthreads OS/400 Pthreads versus the POSIX standard, the Single UNIX...
var createMutex = require ( 'read-write-lock' ) var mutex = createMutex ( ) mutex . writeLock ( function ( release ) { // lol I've got a write lock which means that nobody else can do anything ...
一个Windows下C++读写锁的代码,实现共享读,独占写
The information contained herein is subject to change without notice.An Overview of Kernel Lock ImprovementsDavidlohr Bueso & Scott NortonLinuxCon North... Read/write semaphores6. Read/write [spin]locks
读写锁 ... 仅在定义了 READ_WRITE_LOCK_SUPER 时才公开。 表现 定义: 首先,让我们创建一些对象: k: a lock R: number of readers W: number of writers 为简单起见,假设我们有 1 个操作/读取器和
In this chapter, we will cover: 1.Synchronizing a method; 2.Arranging independent ... 5.Synchronizing data access with read/write locks 6.Modifying Lock fairness 7.Using multiple conditions in a Lock
For each opened file, additional information is displayed: handle value, read/write/delete access, file position, the process that opened the file, and more... Optionally, you can also close one or ...
lock tables user read;//读锁定表 unlock tables;//解锁 lock tables user read local;//本地读锁定表,其他线程的insert未被阻塞,update操作被阻塞 lock table 写锁定 如果一个线程在一个表上得到一个 write锁,...
int i2c_read_reg(char *dev, unsigned char *buf, unsigned slave_address, unsigned reg_address, int len) { struct i2c_rdwr_ioctl_data work_queue; unsigned char w_val = reg_address; int ret; ...
High-performance, Low-power Atmel AVR 8-bit Microcontroller 􀁺 Advanced RISC Architecture ...􀁺 True Read-While-Write Operation ̶ Programming Lock for Software Security
True Read-While-Write Operation – 512 Bytes EEPROM Endurance: 100,000 Write/Erase Cycles – 512 Bytes Internal SRAM – Up to 64K Bytes Optional External Memory Space – Programming Lock for Software ...
Discuss how lock manager uses lock mode, lock resources, and lock compatibility to achieve transaction isolation. Describe the various transaction types and how transactions differ from batches....
read---port.readable.getReader()的读取字节数组方法 write---port.writable.getWriter()的写入方法 ———————————————— 版权声明:本文为CSDN博主「ZhangY1217」的原创文章,遵循CC 4.0 BY-SA版权...
第6章 Read-Write Lock——大家想看就看吧,不过看的时候不能写喔 第7章 read-Per-Message——这个工作交给你了 第8章 Worker Thread——等到工作来,来了就工作 第9章 Future——先给您这张提货单 第10章 Two-Phase...
数据库编程 锁定与解锁 课程目标 了解 —— 锁定和解锁的概念; 掌握 —— 锁定和解锁的设置; 锁定与解锁 MySQL提供了LOCK TABLES语句来锁定当前线程的表,语法格式如下: ...LOCK TABLES XS READ; 说明:LOCK TABLE
6、Read-Write Lock ———— 大家想看就看吧,不过看的时候不能写哦 7、Thread-Per-Message ———— 这个工作交给你了 8、Worker Thread ———— 等到工作来,来了就工作 9、Future ———— 先给您这张提货单 10...
轻松读取数据,更改esn,meid Unlock spc, MSL, SPC3, FSK, OTKSL, User Lock, MIN lock, SIM LOCK Programming: MIN, MDN, IMSI, NAM, PRL file, Phone Settings ... Read Write EEPROM, RAM, SDRAM area)
if (b->writepos >= BUFFER_SIZE) b->writepos = 0; /* Signal that the buffer is now not empty */ pthread_cond_signal(&b->notempty); pthread_mutex_unlock(&b->lock); } /*---------------------------...