RwLock: Reader-Writer lock
Project description
RwLock: Reader-Writer lock
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.
After 1.6.0, RwLock can support multi-thread(default) and multi-process.
For multi-process scenario, use rwlock = RwLock(cross_process=True)
Usage
Install
pip install cy_rwlock
- download latest version from https://pypi.org/project/cy_rwlock/#files
Example
from rwlock import RwLock
rwlock = RwLock()
### READER
rwlock.acquire_r()
# read...
rwlock.release_r()
# OR
with rwlock.lock_r():
# read...
### WRITER
rwlock.acquire_w()
# write...
rwlock.release_w()
# OR
with rwlock.lock_w():
# write...
Unittest
- local(windows)
- run
scripts\run.bat
- run
- github
- auto run when push
Deploy
- PyPI version
- convertd from git tag
- see setup.py: convert_version()
- convertd from git tag
- local(windows)
- run
scripts\deploy.bat
- run
- github -> PyPI
- When release in github
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.7.2.tar.gz
(4.4 kB
view hashes)
Built Distributions
Close
Hashes for cy_rwlock-1.7.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5aafe6e6c176b3b3c364179513d1f292ef45c09eb8d84549230254240c65075 |
|
MD5 | d74fd115347699ff56c8969638742135 |
|
BLAKE2b-256 | bdb10393e7eb11f9b3f240374fed787f6edfebf9903fd426d884f4ab03bc1172 |
Close
Hashes for cy_rwlock-1.7.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77679e69c10684ce0a4dc15bde9f46203ebd554124d03462a08596b6044db35c |
|
MD5 | 31311089e6db91667b5534a7874a1e3f |
|
BLAKE2b-256 | 4f769b7b1645b67fd17fcc3bd42d87f90979c9d25e3c1e481643951843f3813e |