Re: fread/fwrite/fflush bug
Re: fread/fwrite/fflush bug
- Subject: Re: fread/fwrite/fflush bug
- From: "Scott D. Davilla" <email@hidden>
- Date: Tue, 8 Jan 2008 10:38:12 -0500
Title: Re: fread/fwrite/fflush bug
I've found
what I consider to be a stream IO bug. The code below can be
compiled with g++ to easily illustrate the problem. Here's what's
happening:
1. Open a file for writing (using fopen(,
"w") ) and write some data to the file
2. Flush the writer using
fflush()
3. Open a second stream to the file for reading
only using fopen(., "r")
4. Read some bytes using fseek() & fread() to
confirm the reader can see the data written in step
1
5. Have the writer update 1 byte using
fwrite()
6. Flush the writer using
fflush()
7. Using the read stream, read the byte written by
the writer in step 5 using fseek() / fread()
8. You will get the wrong answer here. The
read should return the byte written in step 5 but instead returns the
old value written in step 1.
I too am seeing a similar problem.
In my case, We have one producer thread that does an fopen for write
only, and several consumer threads that do fopen for read only. The
consumer threads are only able to read the number of bytes in the file
that existed when the fopen was called. They never see any additional
data from the producer thread.
These files can be very large, they
are position (x,y) with electron and x-ray events streamed in realtime
from networked hardware.
This is a real problem with our
existing code as it's design depends on the above ability. We just
moved from CFM to Mach-O (yea, yea, I know). Works fine with CW and
CFM (and Borland, we are cross-platform).
Any suggestions for a
solution?
Scott
--
-----------------------------------------------------------------------
Scott D.
Davilla
Phone: 919 489-1757 ext 13 (tel)
4pi Analysis,
Inc. Fax: 919
489-1487 (fax)
3500 Westgate Drive, Suite
403 email: email@hidden
Durham, North Carolina
27707-2534 web:
http://www.4pi.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden