libsnooze event reservation #5
Labels
No Label
bug
duplicate
enhancement
help wanted
invalid
question
todo
wontfix
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
Blocks
#3 Next gen
deavmi/tristanable
Reference: deavmi/tristanable#5
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What is this?
When we call
dequeue()
that would be the first time we callwait()
actually and only then is a pipe pair made.Therefore the exists a potential race to the first
dequeue()
call of a freshly madeQueue
and theenqueue()
call that theWatcher
would make (which it could do before). In the case whereby theWatcher
makes the firstnotifyAll()
call, well there is no pipes to write too and hence ourdequeue()
would block forever.Solution ✅
The easiest way to ensure that the the thread which created the
Queue
and then registered it later has a pipe-thread pair would be for theQueue
constructor to callwait(0)
such that it blocks the calling thread whilst creating/constructing theQueue
but also immediately returns as no bytes are available to be read from the pipe (according to libsnooze's use ofselect()
), this will however create a pipe pair for us via theensurePipePair()
call of libsnooze.The calling thread
This ensures that atleast in our unit test it will work. The unit test in
Watcher
shows us the normal usage one would expect from tristanable. TheQueue
-constructingThread
will be usable in this use case at least.If you passed the
Queue
to another thread then it would only register on the first call todequeue()
. This usage if a little weird, you should construct it on the thread doing the dequeuing. Doesn't make sense to have them split, also what doesn't necessarily make sense is multiple threads dequeuing (from the sameQueue
) - one can do it but its odd, it would be a race to whoever can unlock the mutex first.Here is the solution in code form:
As of commit
2fa77e639ff16ef07db55a5cc70433af3f03ef64
.Fixed in commit
2fa77e639ff16ef07db55a5cc70433af3f03ef64