[PipeSleepStrategy] fix specific state and sleeper count race
Introducing a lock for each specific state greatly simplifies the algorithm, fixes a race and I expect it to be rather cheap. The fact that we have to check two conditions before sleeping and prepare resources dependent on those makes the algorithm complex and racy. We skip sleeping if we were notified specifically or the global sleeper count was less than 0. If we check our local state first and decrement the global sleeper count later. We could receive a notification after the decrement which causes the worker to skip sleeping making the decrement wrong and the whole counter unsound. Checking the local state first and mark us as sleeping preparing a read for the specific pipe has the problem that after the decrement if we should skip sleeping we have prepared sqes which we should submit needlessly because we are not actually sleeping. Ans decrementing the global count first has the same problem as the first one where the decrement is wrong if we skip sleeping after wards breaking the counter. All this is prevented by locking the specific state while we check both conditions.
parent
c57a23be
No related branches found
No related tags found
Loading
Please register or sign in to comment