switched locking of threads to single flag

Threads now (safely) decrement an integer which is set to the number of
tasks that need to be finished. They set a flag when it goes to 0. The
Solver then continues and resets the flag.