TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
48
11.9k
Overwriting the same file each loop.
Aug 26 2019 10:36 AM
I am creating a program that will move a car object, with 2D coordinates, around a map. The coordinates are in the form of two doubles, and I want to write these to a text file about once every few seconds. The data will overwrite any existing data. The idea is that if the program crashes or is terminated, then the coordinates can be loaded upon restarting the program.
The catch is that I want to run multiple instances (less than 50 for now) of this program to simulate multiple cars. Each "car" will have its own coordinates file. I am wondering if I need to do anything special to assure that there will not be a conflict when any of these cars are writing their coordinates to disk. Since the program instances are started at different times, their loop may or may not coincide with another program's loop timing.
Right now I am only testing the initial car, so I want make sure I design it to support multiple instances. I am opening the file only once and then overwriting the data in each loop (every 2 seconds). I know that sometimes programs will run fine for 10 minutes, maybe an hour, but then crash later when a rare conflict occurs, so I want to avoid that as I want my program to be able to run as long as it is needed.
Reply
Answers (
2
)
Save data entered from two forms
.ics file attachment is missing in google mail