473,503 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Concurrent updates of the same file

I have a C++ program which appends new text to a file. Multiple
instances of this program may run concurrently, hence there is a
possiblity that 2 or more instances (say C1 and C2) of this C++ program
will be modifying the file at the same time.

I want to make sure that C1 can finish appending it's changes to the
file, before C2 starts to append its changes.

How do I handle this concurrently update issue so that the changes made
by C1 and C2 are not interpersed with each other's?

Feb 16 '06 #1
6 2897
John Smith wrote:
I have a C++ program which appends new text to a file. Multiple
instances of this program may run concurrently, hence there is a
possiblity that 2 or more instances (say C1 and C2) of this C++ program
will be modifying the file at the same time.

I want to make sure that C1 can finish appending it's changes to the
file, before C2 starts to append its changes.

How do I handle this concurrently update issue so that the changes made
by C1 and C2 are not interpersed with each other's?


I don't think you can, using C++ alone. The word "concurrent" gives it
away, since C++ does not support concurrency or threads.

You'll have to use OS specific means to lock the file during the write.
There should be a suitable group to ask that question in. It would be
off topic here.

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Feb 16 '06 #2

Ben Pope wrote:
John Smith wrote:
I have a C++ program which appends new text to a file. Multiple
instances of this program may run concurrently, hence there is a
possiblity that 2 or more instances (say C1 and C2) of this C++ program
will be modifying the file at the same time.

I want to make sure that C1 can finish appending it's changes to the
file, before C2 starts to append its changes.

How do I handle this concurrently update issue so that the changes made
by C1 and C2 are not interpersed with each other's?


I don't think you can, using C++ alone. The word "concurrent" gives it
away, since C++ does not support concurrency or threads.

You'll have to use OS specific means to lock the file during the write.
There should be a suitable group to ask that question in. It would be
off topic here.


Well, you can always create a lock file and do such checking yourself.

Feb 16 '06 #3
when C2 recognizes the lock file created by C1, how can I make C2
"busy-wait" until the lock file is removed by C1?
how about using an "infinite" while loop?

Feb 16 '06 #4
ro**********@gmail.com wrote:

Ben Pope wrote:
John Smith wrote:
I have a C++ program which appends new text to a file. Multiple
instances of this program may run concurrently, hence there is a
possiblity that 2 or more instances (say C1 and C2) of this C++
program will be modifying the file at the same time.

I want to make sure that C1 can finish appending it's changes to
the file, before C2 starts to append its changes.

How do I handle this concurrently update issue so that the
changes made by C1 and C2 are not interpersed with each other's?


I don't think you can, using C++ alone. The word "concurrent"
gives it away, since C++ does not support concurrency or threads.

You'll have to use OS specific means to lock the file during the
write. There should be a suitable group to ask that question in.
It would be off topic here.


Well, you can always create a lock file and do such checking yourself.


Please explain how you eliminate race conditions with standard C++
mechanisms.

Brian
Feb 16 '06 #5
John Smith wrote:
How do I handle this concurrently update issue so that the changes made
by C1 and C2 are not interpersed with each other's?


You should use some external lib, like [yet] external Boost:
http://www.boost.org/doc/html/threads.html

Feb 17 '06 #6
"John Smith" <wl*****@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
I have a C++ program which appends new text to a file. Multiple
instances of this program may run concurrently, hence there is a
possiblity that 2 or more instances (say C1 and C2) of this C++ program
will be modifying the file at the same time.

I want to make sure that C1 can finish appending it's changes to the
file, before C2 starts to append its changes.

How do I handle this concurrently update issue so that the changes made
by C1 and C2 are not interpersed with each other's?


Normally this is done by some type of file locking.

One way would be to use mutexes that are recognizable between processes
(windows has them, not sure if *nix does).
Feb 17 '06 #7

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

Similar topics

8
1555
by: Paul Rubin | last post by:
Shelve uses dbm and pickle to make a persistent object store. The "db" in "dbm" stands for "database" and while I didn't expect full ACID capability, I'd have thought there'd be at least some...
11
5420
by: Durai | last post by:
Hi All, I tested "concurrent testing" in MySQL. It works fine. But I couldn't do in PostgreSQL 7.3.4 on HPUX IPF. I got deadlock problem. I used the PHP script to update table( one script...
1
1194
by: Babz | last post by:
Hi, How I can prevent concurrent updation of a records in .net. I am using Dataset which is disconnected from the data source. In this situation if two users opens the same record, modifies the...
3
1259
by: manmit.walia | last post by:
Hello All, I am stuck on a problem with updating an XML file. Here is what my final solution suppose to do. I have a web form which displays all users that are authorized for recieving a...
14
2245
by: vunet.us | last post by:
Hi, I would like to use flat file data storage instead of database. Since I am new to it, I am wondering: What text file extension is a safe one to store my data online and how cost- and...
4
11908
by: ms.wcchan | last post by:
Dearest I.T. professional, I am now doing a survey and would like to ask all customers to submit the questionnaire online so that I can collect the results in the excel file. What programming...
4
6923
by: vunet.us | last post by:
I want to know if this practice is effective and secure: I have been thinking about storing some data, which my users upload, in text files rather than database, since often I do not know how much...
10
4478
by: Frankie | last post by:
It appears that System.Random would provide an acceptable means through which to generate a unique value used to identify multiple/concurrent asynchronous tasks. The usage of the value under...
6
5823
blyxx86
by: blyxx86 | last post by:
Good Morning Everyone, I am making a PHP web frontend for a MySQL database. I have finally started to create the UPDATE portions of the website and am wanting some opinions/feedback as to what...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
382
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.