Summary:
When a thread pool worker becomes idle, it follows these steps:
1. Checks the task queue
2. Adds itself to the waiting workers list
3. Waits on a condition variable for new work
However, a race condition can occur if a task is added to the queue immediately after the worker checks it but before it begins waiting. This results in:
- The worker waiting on the condition variable
- While the task queue is non-empty (causing a potential deadlock)
Fixed by updating logic after worker was added to the idle workers list.
The worker tries to check task queue, if queue is empty, then it waits on condition.
After condition notified it checks to termination and task sent via NotifyWorker.
Previously all those checks were done after condition trigger.
Jira: DB-17504
Test Plan: ThreadPoolTest.SingleWorker
Reviewers: huapeng.yuan
Reviewed By: huapeng.yuan
Subscribers: ybase
Tags: #jenkins-ready
Differential Revision: https://phorge.dev.yugabyte.com/D45226