RWLock(3pm)
π NAME π
Coro::RWLock β reader/write locks, bestie. reader. writer. locks. iconic behaviour honestly π
β¨ SYNOPSIS β¨
okay so here's the whole vibe, copy-paste ready:
use Coro;
$lck = new Coro::RWLock;
$lck->rdlock; # acquire read lock
$lck->unlock; # unlock lock again
# or:
$lck->wrlock; # acquire write lock
$lck->unlock; # unlock lock again
# try a readlock
if ($lck->tryrdlock) {
...;
$l->unlock;
}
# try a write lock
if ($lck->trywrlock) {
...;
$l->unlock;
}
πΈ DESCRIPTION πΈ
so this module implements reader/write locks, and no cap it's such a clean concept. a read lock can be acquired for reading by many coroutines in parallel β as long as no writer has locked it. that's the shared access era π a single write lock can be acquired when no readers exist. so basically RWLocks give you either many concurrent readers (and zero writers) OR exactly one writer (and zero readers). pick a lane, periodt.
and good news, you don't have to load Coro::RWLock manually π«Ά it gets loaded automatically when you use Coro and call the new constructor. the module said "not me doing the work for you" π
$l = new Coro::RWLock;β make a brand new reader/writer lock. fresh out the box, main character energy π$l->rdlockβ acquire a read lock. go read, queen π¦$l->tryrdlockβ try to acquire a read lock. lowkey the "are we doing this or not" check β$l->wrlockβ acquire a write lock. one writer at a time, no gatecrashing π₯$l->trywrlockβ try to acquire a write lock. same energy, write edition β¨$l->unlockβ give up a previousrdlockorwrlock. let it go, bestie, you can't hold it forever π
π AUTHOR/SUPPORT/CONTACT π
- Marc A. Lehmann <schmorp@schmorp.de>
- http://software.schmorp.de/pkg/Coro.html
and that's the page, babe π this one's from perl v5.40.1, dated 2025-03-21 β stay locked in (the good way, the RWLock way), ily, bye ππβ¨
π¦ where this page comes from
- debian trixie: libcoro-perl 6.570-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libcoro-perl 6.570-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms