RwLock: Reader-Writer lock
Project description
RwLock: Reader-Writer lock
Release Note
- V1.2:
- fix version convert issue in setup.py
- V1.1:
- Reduce test time
- Refactoring
- V1.0: first release
Introduction
We can simply protect a shared resource by a lock. But the performance is not good because each reader should run one-by-one.
A Reader-Writer lock can improve the performance by let readers running simultaneously.
By the way, a writer should wait until all readers done. In a frequently read situation, a new reader after the writer can also increase the read count, let read count never decrease to 0. This will starve writer.
RwLock:
- Let readers running simultaneously.
- Exclude "multiple readers" and each writer.
- provide a flag "write_first" to prevent starve writer.
Usage
Install
pip install cy_rwlock
- download latest version from https://pypi.org/project/cy_rwlock/#files
Example
-
Reader
-
from rwlock import RwLock
-
rwlock = RwLock()
-
rwlock.acquire_r() //Do read rwlock.release_r()
- OR
-
with rwlock.lock_r(): //Do read
-
-
Writer
-
from rwlock import RwLock
-
rwlock = RwLock()
-
rwlock.acquire_w() //Do write rwlock.release_w()
- OR
-
with rwlock.lock_w(): //Do write
-
-
full example:
Unittest
- run
scripts\run.bat
Deploy
- run
scripts\deploy.bat
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cy_rwlock-1.4.tar.gz
(3.8 kB
view hashes)