abg-workers: guard bring_workers_down to avoid dead lock

Since bring_workers_down is not atomic, a worker thread can make a racy
read on it while do_bring_workers_down() writes it. That can lead to a
deadlock between the worker thread waiting for more work and
do_bring_workers_down() waiting for the worker to finish.
Address this by guarding all access to bring_workers_down with locking
tasks_todo_mutex. This is likely to be dropped after migrating to newer
C++ standards supporting std::atomic.

	* src/abg-workers.cc(do_bring_workers_down): keep
        task_todo_mutex locked while writing bring_workers_down,
	(wait_to_execute_a_task): rewrite the loop condition to ensure
	safe access to bring_workers_down.

Signed-off-by: Matthias Maennich <maennich@google.com>
1 file changed