replace synchronized closures with explict mutex lock/unlock, remove @num_*_waiting vars