Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latch-And-Spin mechanism. #11

Open
prataprc opened this issue Aug 29, 2019 · 0 comments
Open

Latch-And-Spin mechanism. #11

prataprc opened this issue Aug 29, 2019 · 0 comments
Labels
rdms-doc Contains useful documentation that explains how to use rdms, and its internals.
Milestone

Comments

@prataprc
Copy link
Owner

prataprc commented Aug 29, 2019

Read-Write-Spinlock implements the idea of latch-and-spin mechanism normally used for non-blocking concurrency.

Blocking concurrency can have impact on latency. When operations that require rw-exclusion is going to be quick and short, we can use non-blocking primitives like latch-and-spin.

What is Latch and spin ?

In typical multi-core processors, concurrent read operations are always safe and consistent. But it becomes unsafe, when there is a writer concurrently modifying data while readers are loading it from memory.

Latch-and-lock mechanism can be used when we want to allow one or more concurrent writer(s) along with readers.

Imagine a door leading into a room. This door has some special properties:

  1. The door has a latch and a lock.
  2. A reader can enter the room only when the door is un-locked and un-latched.
  3. A writer can enter the room only when the door is un-locked and, un-latched and, there are no other reader or writer in the room.
  4. Once the door is latched by a writer, no other writer or reader can enter the room because of (1) and (2) properties. But all readers who are already inside the room can finish their job and then exit.
  5. A writer can enter the room only after locking the door, which the writer can do only after all the readers have exited.
  6. When trying to acquire read-permission or write-permission, the caller thread shall spin until all the conditions from (1) to (5) are met. Once a thread acquires necessary permission it can continue to finish its job and then release the permission.
@prataprc prataprc changed the title LatchAndSpin mechanism. Latch-And-Spin mechanism. Aug 29, 2019
@prataprc prataprc mentioned this issue Aug 29, 2019
62 tasks
@prataprc prataprc added the rdms-doc Contains useful documentation that explains how to use rdms, and its internals. label Aug 29, 2019
@prataprc prataprc added this to the Milestone1 milestone Sep 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rdms-doc Contains useful documentation that explains how to use rdms, and its internals.
Projects
None yet
Development

No branches or pull requests

1 participant