Skip to contentSkip to conversation

Corrupted files when using fwrite() or fprintf()

Xenomai Krause, Holger 2 participants 3 messages Jan 22, 2015 – Jan 26, 2015 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Hello all Xenomai developers.

We run Xenomai 2.6.3 with posix skin activated.
In one thread with priority 0 - so it runs in secondary mode - we use file io with fopen, fwrite, fclose instructions.

When writing a file via fwrite or fprintf we get a problem :
Just one part (the first) of the file has been written. The rest of the file is missing although the fwrites/fprintfs have been executed.

The sequence is like this:

// Open file
fopen();

// Write the first part
fwrite();

// Switch the state machine to the next state to prepare the next part // to be written to the file.
// So the system can do other things - other threads come up and so on

// Write the second part
fwrite()

// Switch the state machine to the next state to prepare the next part // to be written to the file.
// So the system can do other things - other threads come up and so on

...

// Finally close the file
fclose();

In this situation we get some kind of a timing issue:
Only the first part of the file has been written - but the file is closed correctly.
The statemachine works correctly so all the fwrites haben been executed but ony the first fwrite works on the filesytem.

In another thread we use the same mechanism but everythings works there.

When I debug the code everythings works.

When I switch all the threads to linux everything works (of course without realtime) - the file is OK.

When I insert a rt_task_sleep() after the fwrites everythings works if the delay time is big enough (>100ms).

Switching all threads in our system to priority 0 (so that an RT thread cannot catch the hole CPU time and the system cannot write data to disk) does not change anything.

Does anybody have similar problems?

Best regards,
Holger Krause.

#1 lore raw
Quoted 3 lines · Holger

Hello all Xenomai developers.

We run Xenomai 2.6.3 with posix skin activated.

Do you have the same problem with Xenomai 2.6.4 ?

Signature · 1 line
					    Gilles.

A message that is not in the archive (sent off-list or not yet received): 2DC6992080CF3541B10F42EBF0B5C30342F644D7@SMExchange01.siebmeyer.org

#3 lore raw
Quoted 5 lines · Holger

Hello,

in version 2.6.4. the error is still present but there is a small change:
The file is now bigger, there are more lines in the file not just the first one.

Ok. Could you post a reduced self-contained test case allowing us to reproduce the issue ?

Signature · 1 line
					    Gilles.