I few days ago I sent an email to the llvm-dev mailing list, describing a list of problems that the user could face with concurrent ThinLTO processes with caching enabled. More specifically, I identified a data race condition and other inefficiencies, caused by resource sharing problems. Here it is for the reference.
http://lists.llvm.org/pipermail/llvm-dev/2018-March/122046.html
After the long subsequent discussion on the mailing list we decided to implement the following straightforward solution described in this proposal.
Namely,
a. Place temp file to the same place where the caching directory is (instead of creating it the directory pointed to by TMP/TEMP variable). This will help to prevent using non-atomic rename and falling back to non-atomic "direct" write to the cache file.
b. if rename failed do not write to the cache file directly (direct write to the file is non-atomic and could cause data race conditions).
c. if cache file doesn't exist (e.g., because 'rename' failed or because some other reasons), bypass using the cache altogether.