Coder Social home page Coder Social logo

rwlock's Introduction

RWLock is a C++ library meant to provide light-weight read-write locks
for Windows thread synchronization. RWLock is intended to be both
versatile and lightweight, and comes in a few different flavors.

RWLock is developed and maintained by Mahmoud Al-Qudsi
<[email protected]> of NeoSmart Technologies <http://neosmart.net/>

Pthread's rwlock objects provide a high-performance means of allowing
either multiple readers to access a resource simultaneously or a
single writer. Windows did not have an equivalent thread
synchronization primitive until Windows Vista was released. However,
most software developers still target Windows XP and above, so this
library should come in handy to fill in the gap.

Non-IPC RWLock() implementations will automatically use Microsoft's
SRW Locks behind the scene if run on Windows Vista or above.

Unlike pthread_rwlock_t and SRW Locks, RWLock can also be used for
interprocess read-write synchronization via placement of a single
intptr_t object memory-mapped or stored in a shared data segment.

Usage:

RWLock comes in four distinct flavors, each with different features
and different performance characteristics.

All four RWLock implementations share a common locking/unlocking API,
though they differ somewhat in initialization:

void StartRead();
void EndRead();
void StartWrite();
void EndWrite();

The usage is completely straight-forward. Readers call StartRead() to
access a shared resource for reading and EndRead() at the end of
accessing the shared resource. Writers do the same with StartWrite()
and EndWrite(). These functions take no parameters and return no
values.

The different RWLock flavors are listed below, from fastest to
slowest. You should use the fastest object that meets your
requirements:


1. RWLock()

* This is the fastest and lightest RWLock flavor 

* RWLock cannot be used for cross-process synchronization

* RWLock does not support reentrance(StartRead() being called multiple
  times by the same thread before EndRead() is called)

* RWLock does not support calling StartRead() after calling
  StartWrite() but before calling EndWrite()

* On Windows Vista/7/8, this RWLock implementation will dynamically
  switch to an SRW Lock underneath the hood for optimum performance.


2. RWLockReentrant()

* RWLockReentrant supports reentrance

* RWLockReentrant supports calling StartRead() after StartWrite()

* RWLockReentrant cannot be used for cross-process synchronization

* On Windows Vista/7/8, this RWLock implementation will dynamically
  switch to an SRW Lock underneath the hood for optimum performance.


3. RWLockIPC(intptr_t *lock, LPCTSTR guid)

lock: pointer to an intptr_t object located in a shared data segment

guid: unique string used to create the named synchronization objects

* RWLockIPC can be used for cross-process synchronization

* RWLockIPC does not support reentrance

* RWLockIPC does not support calling StartRead() after calling
  StartWrite()


4. RWLockIPCReentrant(intptr_t *lock, LPCTSTR guid)

lock: pointer to an intptr_t object located in a shared data segment

guid: unique string used to create the named synchronization objects

* RWLockIPCReentrant can be used for cross-process synchronization

* RWLockIPCReentrant supports reentrance

* RWLockIPCReentrant supports calling StartRead() after calling
  StartWrite()

rwlock's People

Contributors

mqudsi avatar

Stargazers

<I°_°I> avatar  avatar BasicP avatar  avatar Mohammed Ebrahim avatar  avatar allenhekexin avatar Alexey Dyumin avatar Alexander Rechitskiy avatar Hossam Ayman avatar mak avatar Jordan Cristiano avatar  avatar  avatar Yateng Hong avatar spock avatar wyrover avatar Drogunov Igor avatar ivy avatar  avatar Patrick Wyatt avatar Rory Petty avatar Camilo E. Hidalgo Estevez avatar

Watchers

 avatar James Cloos avatar skyformat99 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.