3 ms·
I don't know what you mean by "a file is a singleton": I have many files on my computer, and I can open any of them multiple times.
by nedbat 4y ago
I don't know what you mean by "a file is a singleton": I have many files on my computer, and I can open any of them multiple times.
- postalrat 4y agoAnd what happens when all those places you have the file opened want to write or read the file?
- gpderetta 4y agoThey need to use some form if mutual exclusion? Same as for non-singleton objects in a process.
- bdcravens 4y agoIn most cases nothing, the OS or applications will naively read it or write what they believe the current state to be.
- philihp 4y agoYou fclose the handle when you're done, or you create some kind of synchronized semaphore, if you wanna be extra. The issue is really around having multiple handles for writing (not just reading or appending), and the number of times you actually have this problem here is vanishingly rare.
- nedbat 4y agoI'm not saying it's a good idea to open it more than once at the same time, but nothing is preventing me from doing it, so I'm not sure what is meant by, "a file is a singleton"?