Skip to main content

RwLock: Reader-Writer lock

Project description

Coverage

RwLock: Reader-Writer lock

Release Note

  1. V1.2:
    1. fix version convert issue in setup.py
  2. V1.1:
    1. Reduce test time
    2. Refactoring
  3. 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:

  1. Let readers running simultaneously.
  2. Exclude "multiple readers" and each writer.
  3. provide a flag "write_first" to prevent starve writer.

Usage

Install

  1. pip install cy_rwlock
  2. download latest version from https://pypi.org/project/cy_rwlock/#files

Example

  1. Reader

    1. from rwlock import RwLock
    2. rwlock = RwLock()
    3.  rwlock.acquire_r()
       //Do read
       rwlock.release_r()
       
    4. OR
    5.  with rwlock.lock_r():
           //Do read
       
  2. Writer

    1. from rwlock import RwLock
    2. rwlock = RwLock()
    3.  rwlock.acquire_w()
       //Do write
       rwlock.release_w()
       
    4. OR
    5.  with rwlock.lock_w():
           //Do write
       
  3. full example:

    1. https://github.com/cy-arduino/cy_rwlock/blob/master/rwlock/tests/test_rwlock.py

Unittest

  • run scripts\run.bat

Deploy

  • run scripts\deploy.bat

Project details


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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cy_rwlock-1.4-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file cy_rwlock-1.4.tar.gz.

File metadata

  • Download URL: cy_rwlock-1.4.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for cy_rwlock-1.4.tar.gz
Algorithm Hash digest
SHA256 1722b5ed9e20bc8b48c458dc6cefb8cd7f09b8000f06fc5d4b0526acc728ea9e
MD5 07a512353b3fd5bd093735abe75282a4
BLAKE2b-256 e99ffb4638577e4938a29b65db982d21c1f9c9f5a442e636249f715e3a4b141f

See more details on using hashes here.

File details

Details for the file cy_rwlock-1.4-py3-none-any.whl.

File metadata

  • Download URL: cy_rwlock-1.4-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for cy_rwlock-1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5d6b8bade6d7b7fc5bcc6ff510f1e8067a3c1177107e2cb7aa73eb2b031dd1db
MD5 e14eae82ef6c81730eba4cc6c85f131f
BLAKE2b-256 2d6c505089266e269a76b5f778e76d22cd282e744a1f9db875c2ecba26382eec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page