Readers-writer lock for Nim.
Example:
import threading/rwlock import std / os var rw = createRwLock() var data = 0 proc worker = for i in 0..<100: writeWith rw: let tmp = data data = -1 sleep 1 data = tmp + 1 var threads: array[10, Thread[void]] for i in 0..<10: createThread(threads[i], worker) for i in 0..<100: readWith(rw, assert data >= 0) joinThreads(threads) assert data == 1000
Procs
proc `=destroy`(rw: RwLock) {.inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc beginWrite(rw: var RwLock) {....raises: [], tags: [], forbids: [].}
- Acquire a write lock. Source Edit
proc createRwLock(): RwLock {....raises: [], tags: [], forbids: [].}
- Source Edit