Listen for shutdown in thread loops.

This way we don't need to use wait_for(), much better.
Also because there are slightly more correct cond vars on win32.