New lock creation in gen_rlock() #14
Unanswered
mirza-ali-ctct
asked this question in
Q&A
Replies: 1 comment
-
Hello @mirza-ali-ctct To answer your question, a.gen_rlock() .. means generate a reader lock from the parent context 'a' For example the following creates two child reader lock and two child writer lock from the same parent context a: from readerwriterlock import rwlock
a = rwlock.RWLockFairD() # This creates a context
areader1 = a.gen_rlock()
areader2 = a.gen_rlock()
awriter1 = a.gen_wlock()
awriter2 = a.gen_wlock() They are all related to the same context 'a' Therefore: with awriter1:
with awriter2: # awriter2 won't ever be able to acquire a lock since it is already locked by awriter1
# won't ever reach this And Therefore: with areader1:
with areader2:
# This is reacheable because readerwriter locks allows more than one reader to lock at the same time And Therefore: with areader1:
with awriter1: # awriter1 won't ever be able to acquire a lock since it is already locked by areader1
# won't ever reach this You could also create another context:
And the state of the locks from context 'a' and those from 'b' would not affect each other. Hope it explains better the usage |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In the give example:
do these
gen
functions create newLock
instance? I have a scenario where I wanna take read lock multiple times and wondering the implication of this lock creation approachBeta Was this translation helpful? Give feedback.
All reactions