[fpc-devel] Exact details for RTLeventWaitFor and related ?
fpc at mfriebe.de
Sat Aug 22 02:44:15 CEST 2020
I am tracing a race condition in lazCollections TLazThreadedQueue
What is supposed to happen in the following case:
2 or more threads are waiting on the some event
1 thread sets it
I expect that wakes up exactly ONE thread (never mind wich)?
If no one resets the event (NO call to RTLeventResetEvent), then that
does not change anything? It is still just the one thread that got woken up?
Thanks for any feedback
TLazThreadedQueue.PopItem works like this
If item avail then return item
// race condition between those lines.
If item avail then return
If 2 or more reading (popping) threads are both at the indicated location,
and if during this time 2 or more items are added
then there is a problem (I believe)
adding (pushing) an item does
adding 2 items (with no pop in between) calls Set twice
It is unclear if the 2nd RTLeventSet has any effect ?
According to my tests:
- I "sleep()" 2 listeners at the critical line, so they both will
WaitFor after the sleep
- while they sleep I add 2 items (2 calls to RTLeventSet, no one
- Both start RTLeventWaitFor
=> only one listener wakes up.
Is that the expected behaviour?
More information about the fpc-devel