Fix a situation where some threadpool work items are never executed.

Fixes #6349