P
Pablo
At my current job I've been tasked with maintaining a very old C++
application written largely in ANSI c++ in what I believe to be with an old
DOS based Borland compiler. I'm trying to add a simple event logging
component to the application. Initially I began with a simple:
[...]
fstream dumpfile
dumpfile.open(fname,std::ios_base:ut | std::ios_base::app);
[...]
//Event log occurs
dumpfile << dumptext << std::endl;
[...]
But I realized that I would (and did when I started testing) have a problem
because this DOS app is used in a multiuser environment. Competing users
will overwrite eachothers entries if they occur at the same time.
Previously, my pure ANSI c++ experience has been in primarily single
computer/user environs- and any multiuser experience usually got into OS
specific extentions so this never was an issue.
My question is, what methods would someone suggest to me to allow multiuser
access (using any object available in an ANSI environment) which would avoid
such multiuser issues as described above.
Having some experience with race conditions in other os/languages unrelated
to C++, I came up with one idea-- which seemed kludgey. That is to first
check to see if a 'locking' control file exists in a common directory. If
it sees a file there, assume someone else has control of the log file, wait,
repeat step one. If it doesn't find a locking file, create it and write
some unique set of bytes determined by the individual instance (user) of the
app. Wait a 'reasonable' time, then re-read the bytes-- if said bytes
remain as the unique identifier- I can conclude that I have control and can
then open the real log file, write, then delete the 'locking' file when the
write and buffer flush(close) on the log file are complete.
Again, that's the only thing I've come up with. Any advice/criticism (or
especially new ideas) would be appreciated. Thanks in advance,
Paul
application written largely in ANSI c++ in what I believe to be with an old
DOS based Borland compiler. I'm trying to add a simple event logging
component to the application. Initially I began with a simple:
[...]
fstream dumpfile
dumpfile.open(fname,std::ios_base:ut | std::ios_base::app);
[...]
//Event log occurs
dumpfile << dumptext << std::endl;
[...]
But I realized that I would (and did when I started testing) have a problem
because this DOS app is used in a multiuser environment. Competing users
will overwrite eachothers entries if they occur at the same time.
Previously, my pure ANSI c++ experience has been in primarily single
computer/user environs- and any multiuser experience usually got into OS
specific extentions so this never was an issue.
My question is, what methods would someone suggest to me to allow multiuser
access (using any object available in an ANSI environment) which would avoid
such multiuser issues as described above.
Having some experience with race conditions in other os/languages unrelated
to C++, I came up with one idea-- which seemed kludgey. That is to first
check to see if a 'locking' control file exists in a common directory. If
it sees a file there, assume someone else has control of the log file, wait,
repeat step one. If it doesn't find a locking file, create it and write
some unique set of bytes determined by the individual instance (user) of the
app. Wait a 'reasonable' time, then re-read the bytes-- if said bytes
remain as the unique identifier- I can conclude that I have control and can
then open the real log file, write, then delete the 'locking' file when the
write and buffer flush(close) on the log file are complete.
Again, that's the only thing I've come up with. Any advice/criticism (or
especially new ideas) would be appreciated. Thanks in advance,
Paul