2 FILE fopen on same file

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

2 FILE fopen on same file

1,283 Views
lucky06200
Contributor II

Hi,

I want to open 2 FILE (fopen) on same path:

  • A task will fopen FILE for writing in append mode (producer)
  • A second task will open same path to read written data from (consumer)

This seems not to work. Consumer always reads EOF in spite of producer writes in the file.

If producer closes the file, then it seems to work. But, this is not realtime.

I have MQX 4.0 (not 4.01), on Kinetis K60 custom board.

MFS device is SD card.

Would this application be possible ?

Some idea ?

Labels (1)
Tags (3)
0 Kudos
Reply
2 Replies

762 Views
pavel_chromy
NXP Employee
NXP Employee

Dear Lucky,

I am afraid that this approach would not work reliably even if the flushing is performed after the write.

Current design of MFS simply does not allow this. I am even surprised that you were successfully able to open the file the second time at all, if it was already open for writing. A file may be opened multiple times, but only for reading.

If you need to use producer/consumer model like a pipe I suggest you looking at MQX IPC (message queues might also suit well).

Best regards, Pavel

0 Kudos
Reply

762 Views
zhiyangzhang
Contributor III

Maybe, when read and write the same file on the file system, a flush operation is often required because there is only one buffer used for read and write. When the producer closes the file, a flush operation is done. You may try  _io_fflush() first  detailed on the MQX MFS user guide page 24 whenever you do a read operation.

0 Kudos
Reply