Open phoenicyan opened 2 weeks ago
Hi.
That does seem to be an effect of OS scheduling. The thread looping on WaitUnlimitedWaitEx
gets to lock the UnlimitedWait's internals again before the thread trying Add
has a chance of succeeding. Adding Sleep
makes the scheduler give other threads a chance. Probably even Sleep(0)
will be sufficient.
But I'll think of replacing the locking mechanism so it doesn't happen, or happens less.
This whole issue is an effect of the current limitation of WaitUnlimitedWaitEx
waiting while its internal structures are locked. I have an idea how to improve it, but it's more complex than I initially thought, so no ETA.
I initially tried with Sleep(0), and it improved the situation, but still, from time to time, I noticed a delay. You can see usage of the UnlimitedWait in this repo: github.com/phoenicyan/pgnprofiler.
I will think about a better solution for the issue. Will appreciate if you can bring one as well. Thanks!
Hello! I started using the UnlimitedWait object, and it worked great until I needed to dynamically add sources of notifications with AddUnlimitedWaitObject(). In one thread I have loop calling WaitUnlimitedWaitEx(), and in another thread trying to call AddUnlimitedWaitObject(). I noticed that sometimes it results in locking for some random time because WaitUnlimitedWaitEx() is not returning after 25 milliseconds. I currently do not understand the nature of the issue, and how it could be fixed. Maybe this is not an issue in the UnlimitedWait, but a bug in my code. Thank you!
I think I made it work (at least cannot reproduce the issue) by adding Sleep at the end of loop:
But I'm not sure why the Sleep made the difference.