Problem with parallel execution: synchronizing threads