Comments (8)
I've written a write-preferring RWLock. https://gist.github.com/CMCDragonkai/4de5c1526fc58dac259e321db8cf5331
from async-mutex.
A RW lock is a possibility, but would most likely by a separate mutex class. Do you have a usecase in mind?
from async-mutex.
This was my attempt using async-mutex
. It's read-preferring.
from async-mutex.
https://gist.github.com/CMCDragonkai/4de5c1526fc58dac259e321db8cf5331
from async-mutex.
Sorry for my late response, life came in the way and I forgot to reply 😏 Yes, that implementation looks fine and valid. Actually, I like it better than the thought of adding it to the library. If that is fine for you I'll close the issue.
from async-mutex.
I was wondering how to do a write-preferring RWLock, the wikipedia article gives an method using condition variables, but we don't have this here.
A write-preferring one should mean that when a write call is done, it should block and queue up all the reads.
from async-mutex.
That's an interesting exercise 😏 I think the following algorithm with two mutexes and two counters should work:
Reader:
- Lock write mutex
- Check read counter, lock read mutex if it is zero
- Increment read counter
- Release write mutex
- ... [do async stuff]
- Decrement read counter
- Check read counter, release read mutex if it is zero
Writer:
- Check write counter, lock write mutex if it is zero
- Increment write counter
- Lock read mutex
- ... [do async stuff]
- Release read mutex
- Decrement write counter
- Check write counter, release write mutex if it zero
from async-mutex.
Finished up here: https://github.com/MatrixAI/js-async-locks
from async-mutex.
Related Issues (20)
- Possible to have blocking version of isLocked?
- Why can't I release a semaphore? HOT 2
- Please don't deprecate release() function HOT 7
- Bug: Bad execution time for large number of calls on Mutex.runExclusive HOT 3
- mutex.waitForUnlock() bug? HOT 3
- Can `waitForUnlock` be affected by `withTimeout` decorator? HOT 3
- Timing bug inside semaphore for `isLocked()` HOT 7
- what is the limit of thread safe queue limit of asyn-mutex module? HOT 1
- TypeError: objMutex.waitForUnlock is not a function HOT 3
- Communicate value to waiting code
- 0.4 Changelog HOT 1
- Would it always be `locked` if we initialize the semaphore with a negative integer? HOT 1
- Cancel specific pending lock HOT 5
- 0.4.0 not downloadable? HOT 1
- Cancel doesn't work as expected HOT 1
- DELETE ME HOT 1
- Java ReentrantLock implementation (Suggestion)
- Semaphore with negative count (suggestion)
- Request: Priority Queue HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from async-mutex.