I have a strange situation, where rapid file accesses creates weird temporary files.
We are using a file to share data between multiple processes, and an InterProcessLock to synchronize the access to the file.
Pseudocode:
String filename = "myFile.file";
const auto mangledStringForLock = generateSomeMangledStringForTheLock(filename);
InterPorcessLock ipl(mangledStringForLock);
while (someCondition)
{
ipl.enter();
// open file
// read / write something
// close file
ipl.exit();
Thread::sleep(100);
}
This is what I observe in Windows Explorer:
There are temporary files created automatically. When all processes terminate without an error, those temporary files disappear. When a process crashes, sometimes one of these temporary files stays on the disk.
It is worth to note that most of the time, the filename is myFile_temp[something].file, but it can also be myFile.file~[something].TMP (see gif image). It seems like there are multiple things at play here.
I can reproduce the problem even with a single process, if the sleep time is below 100ms.
My questions:
Who is responsible for creating these temp files? I don’t see anything like this in the JUCE code. Also I didn’t find any info if Windows is the culprit here.
Should I care? Is my “data sharing” model at risk? Do I have to transition to shared memory?
Thank you for your reply!
Yes, the processes share the string and locking works.
The weird thing is that this temporary file sits in the same folder as my actual data file so I assumed it had to do with the actual file access. If this temp file was from the InterProcessLock , it would need to know where my data file is. But all it can see is the mangled string, which doesn’t contain any usable information.
The code you quoted has nothing to do with actual files, except for what internally happens in CreateMutexW()
So no, I don’t think this file comes from the lock.
Ok, was a try… I don’t know what your generateSomeMangledStringForTheLock() returns, so it might have the path taken from your filename. But I see now, that it is a plain String.