metasync icon indicating copy to clipboard operation
metasync copied to clipboard

Implement SharedMutex

Open tshemsedinov opened this issue 5 years ago • 0 comments

  • SharedMutex allow us to access shared resource in both ways exclusive and shared.
  • Multiple threads can access resource for read access at a same time
  • Only one threads can access resource for write access at a same time
class SharedMutex {
  status: SM_UNLOCKED | SM_READ_LOCK | SM_WRITE_LOCK,
  async enterRead(callback), // if no callback passed Promise will be returned
  async enterWrite(callback),
  leave(),
  on('status', (status => {})), // or you can subscribe on status change
}

tshemsedinov avatar Mar 16 '19 12:03 tshemsedinov