Improved thread to use condwait (thread CPU usage drops from 100% to 17%)