2 FILE fopen on same file

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

2 FILE fopen on same file

1,455件の閲覧回数
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 返答(返信)

934件の閲覧回数
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 件の賞賛
返信

934件の閲覧回数
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 件の賞賛
返信