Speedup build_queue() by making update_stats() be on-demand using a lock