Re:Singleton Is a Bad Idea
by nedbat on Sunday April 10, 2022 @01:00PM
(#30979037)
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.
[ Parent
| on HN ]
And what happens when all those places you have the file opened want to write or read the file?
You 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.
I'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"?
In most cases nothing, the OS or applications will naively read it or write what they believe the current state to be.