Fixed a condition variable bug with tasks