Properly synchronize worker thread shutdown.