Double-checked locking for SLURM container tasks

When a SLURM job launches N tasks from the same container image, every rank runs the entrypoint in parallel. Commands like ldconfig 1 that write to shared paths ( /etc/ld.so.cache ) collide: multiple tasks try to write the same file simultaneously, the losers get a corrupt or truncated cache, and the job step crashes. One slightly naive fix involves serialization with flock : 1 - flock…