Initialize mutex/condition variables, lock/unlock around condition broadcast.
Only define and use log counter if trace logging is enabled. Causes simultaneous access warnings with running multithreaded otherwise.
Merge branch 'dirk'