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.
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.5.1.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for cy_rwlock-1.5.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d0d0e948bf80ee0c547861936a5db18eb48e58f2af4ba7a5ac3242e04e86820 |
|
MD5 | b6e4877ded1fbb4204a8ce52760cbac4 |
|
BLAKE2b-256 | 89d25ecc9a68c10469e83ea8d0ff6e62c4f31fb9192427ede09c0201b30721e8 |