Mike - EMAIL IGNORED <[EMAIL PROTECTED]> writes: > Requirement: To allow a file to be opened not more than once > at a time. (Emphasis: by any means, within or across > processes.)
That requirement is incomplete. The following "solution" satisfies it, but probably doesn't satisfy your *actual* requirements: char template[] = "tmpXXXXXX"; int fd = mkstemp(template); This file can only be opened once, since no other part of the current process, and no other process knows its name. >> If you want multiple processes to cooperate on writing a single file, >> the proper way to achieve that is with "advisory file locking"; see >> "man flock". > > Thanks for this; I will read it later, but a quick look suggests > that it is what I need. But it doesn't satisfy your requirement (as stated) either -- it doesn't prevent anybody from opening the file multiple times. It probably does satisfy your *actual* requirements, but since you never said what they are, we left to guess at your intentions. It would have been much better for you to think about and state your actual requirements, or your intentions (from which we possibly can deduce your requirements better than you can). > The singleton will open the file once but allow access from different > objects without potential interference, or risk of multiple open > attempts (thereby protecting me from my worst enemy -- myself). Ah, you apparently only have one file that you need to worry about. Then this is a degenerate case of "have your program keep track of files already opened" (the approach I suggested given initial incomplete info). Cheers, -- In order to understand recursion you must first understand recursion. Remove /-nsp/ for email. _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus