2 FILE fopen on same file

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

2 FILE fopen on same file

1,203 次查看
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 ?

标签 (1)
标记 (3)
0 项奖励
2 回复数

682 次查看
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 项奖励

682 次查看
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 项奖励