util/queue: hold a lock when reading num_threads in util_queue_finish