1RWLock(3) User Contributed Perl Documentation RWLock(3)
2
3
4
6 Coro::RWLock - reader/write locks
7
9 use Coro;
10
11 $lck = new Coro::RWLock;
12
13 $lck->rdlock; # acquire read lock
14 $lck->unlock; # unlock lock again
15
16 # or:
17 $lck->wrlock; # acquire write lock
18 $lck->unlock; # unlock lock again
19
20 # try a readlock
21 if ($lck->tryrdlock) {
22 ...;
23 $l->unlock;
24 }
25
26 # try a write lock
27 if ($lck->trywrlock) {
28 ...;
29 $l->unlock;
30 }
31
33 This module implements reader/write locks. A read can be acquired for
34 read by many coroutines in parallel as long as no writer has locked it
35 (shared access). A single write lock can be acquired when no readers
36 exist. RWLocks basically allow many concurrent readers (without
37 writers) OR a single writer (but no readers).
38
39 You don't have to load "Coro::RWLock" manually, it will be loaded
40 automatically when you "use Coro" and call the "new" constructor.
41
42 $l = new Coro::RWLock;
43 Create a new reader/writer lock.
44
45 $l->rdlock
46 Acquire a read lock.
47
48 $l->tryrdlock
49 Try to acquire a read lock.
50
51 $l->wrlock
52 Acquire a write lock.
53
54 $l->trywrlock
55 Try to acquire a write lock.
56
57 $l->unlock
58 Give up a previous "rdlock" or "wrlock".
59
61 Marc A. Lehmann <schmorp@schmorp.de>
62 http://software.schmorp.de/pkg/Coro.html
63
64
65
66perl v5.32.1 2021-01-27 RWLock(3)