473,382 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

using fstream objects in a multiuser environ.


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::out | 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
Jul 23 '05 #1
4 2334
1) Give each user his own error file with a name like
filename_processid_random_number.txt
2) If you want just one global error file for all users... you can make
sure each user app process logs temporally to memory. Periodically
they could open the global error file with exclusive access flush their
log and close the file

Raj

Jul 23 '05 #2

<ra******@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
1) Give each user his own error file with a name like
filename_processid_random_number.txt
2) If you want just one global error file for all users... you can make
sure each user app process logs temporally to memory. Periodically
they could open the global error file with exclusive access flush their
log and close the file

1: Unfortunately I have a specific application need which disallows a
localized or 'many' log files situation. It must be a centralized log file.

2: But my understanding of ANSI c++ is that there is no exclusive open for a
file. Am I incorrect? Is there an ANSI specification for exclusive access
with an FSTREAM object? Or any other file stream object? I'll research
while I wait for a reply.

Paul
Jul 23 '05 #3

"Pablo" <jn**********@comcast.net> wrote in message news:K8********************@comcast.com...
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,


The problem with the lock file is that if one of the users crashes
or has some problems (nic disconnect etc.) the file may not
get cleaned up and you'll be stuck. You probably need some
sort of static instance, maybe a singleton with mutex locks
and a queue mechanism to guarantee that all users work.

Another alternative may be to log to a separate file for
each user and periodically do some sort of merge
into one common file. At least at that point you could
open the files as read only but you still have the problem
that the file may be getting updated while you're merging
it.
Jul 23 '05 #4
I couldn't find one ....

VC++ seems to have a

fstream( const char* szName, int nMode, int nProt = filebuf::openprot
); constructor.

The third argument can used for exclusive access. I am not sure if this
is standard compliant

If you find one, I would be eager to know it as well

Raj

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Erick Bodine | last post by:
I am trying to set a new environment variable on a W2k machine with only partial success. The name("SSID") and value("ASIM") show up correctly in the registry and when I go to "System...
2
by: zeroDontSpamMetype | last post by:
Hi, I've been including code like this in my programs for some time: fstream fin ("c:\\dave.txt", ios::in); if (!fin) { return -1; //or throw an exception, or return false, or //whatever }
11
by: jim.eggleston | last post by:
Windows doesn't have a HOME environment variable, but it does have HOMEDRIVE and HOMEPATH. Could Windows versions of Python automatically populate os.environ with HOME, where HOME =...
1
by: liam_herron | last post by:
I have compiled my boost-enabled C++ module and have it working when I explicity set my LD_LIBRARY_PATH before invoking the python2.4 interpreter. Now I don't want everyone to have to set this...
7
by: jccorreu | last post by:
I've got to read info from multiple files that will be given to me. I know the format and what the data is. The thing is each time we run the program we may be using a differnt number of files,...
9
by: boris.smirnov | last post by:
Hi there, I have a problem with setting environment variable in my script that uses qt library. For this library I have to define a path to tell the script whre to find it. I have a script...
12
by: nathan | last post by:
Hello, Has anyone experienced that records get duplicated by itself. When I look in my tables backend mdb file there are 2 records with the same information. I'm sure the frontend created this...
7
by: Joe P. Cool | last post by:
If I call os.environ.clear in a python program child processes still see the deleted entries. But when I iterate over the keys like so names = os.environ.keys for k in names: del os.environ ...
4
by: Stephen Cattaneo | last post by:
Hello all, I am attempting to execute an automated test (written in Python) via cron. I have to check the HOSTNAME variable as part of the test, oddly under cron the HOSTNAME environment...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.