Fix race between concurrent runs of rdmd
Also protect racy writes to object files and dependency file