Import std.concurrent.locks
RwLock
class
Public Shared Class RwLock<T: Sendable>
A value that many threads can read at once, or one can write while no other reads it. A Read gives what its Function makes of the value, and a Write gives the value what its Function makes of it, which no Read sees half done. A writer that waits goes before the readers that come after it, so it isn't kept waiting forever.
Examples
Const total = RwLock<Int>(0)
total.Write(Function(n: Int) => n + 5)
Expect(total.Read(Function(n: Int) => n * 2) == 10)
Expect(total.Value == 5)std/concurrent/locks.fb, line 286
-
A new RwLock that holds
value. -
What
readergives for the value, which no thread writes meanwhile, though others may read it. Panics when this thread reads or writes it already, in a reader or a writer, which a writer waiting between could keep waiting forever. -
Gives the value what
writergives for it, while no other thread reads or writes it. The old value goes once the Write holds no lock, so a Destroy that its going runs can use the RwLock. Panics when this thread reads or writes it already, which would wait for itself forever. -
A copy of the value, as a Read gives it, or a new value, as a Write gives it.
Report an issue with this page or with FutureBlitz on GitHub.