Fedora Linux Support Community & Resources Center
  #1  
Old 23rd January 2007, 12:46 PM
ata01 Offline
Registered User
 
Join Date: Aug 2006
Posts: 3
Flush Problem

I'm running a multi threaded application on FC4 and I have trouble reading data from a file after writing to it.

I'll describe the scenario in more detail:

file.txt looks like this:

<start of file>
line1
line2
line3
<end of file>

Thread1:

fstream file;

//open file file.txt
file->open("file.txt", fstream::in | fstream::out);

//go to end of file
file->seekp(0, ifstream::end);

//write the string "line4" at eof
string str("line4");
file->write(str.c_str(), str.size());

//flush & close the file
file->flush();
file-> close();

....

*** after the string was written and the file got closed send a message to thread2 that it can read from the file ***

Thread2:

*** wait for message from Thread1 ***

*** after message received: open file, go to eof & read the last line -> error! the string shows "line3". "line4" was not written ***

--------------------------------------------------------

This problem occurs once in a while, so it's hard to catch it.
Also, it seems to me that I have no chance of catching it with a debugger before Thread2 fails reading line4, since the file will be flushed until I get to run the statement that reads from the file.

Anyone encountered problems like this in a multi threaded or even single threaded application?
Reply With Quote
Reply

Tags
flush, problem

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Flush the cat.... Wayne Wibble 40 24th July 2008 05:56 AM
Flush Application Cache dshaw256 Using Fedora 0 28th May 2008 12:58 AM
how do you flush dns in fedora core 5? aliber4079 Using Fedora 0 2nd June 2007 12:05 AM
Is it possible to flush the file cache? bjrosen Using Fedora 5 29th December 2006 06:30 PM
Is there a way to flush the memory? schwim Using Fedora 12 25th June 2006 05:41 AM


Current GMT-time: 01:30 (Wednesday, 22-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat