Summary

Details

I'm writing to /fs/dir1/file1 from thread 1, and writing to /fs/dir2/file2 from thread 2. The files are in different directories (obviously), but live on the same volume.

I noticed that ChaN's FatFs (which the Mbed OS FATFileSystem wraps) has an FF_FS_REENTRANToption, which Mbed OS doesn't support. Would that be necessary for thread safety?

==== Summary ====
I'm using the [[https://github.com/ARMmbed/mbed-os/tree/master/features/filesystem/fat|Mbed OS ##FATFileSystem##]] on an SD card (via [[https://github.com/ARMmbed/sd-driver|##sd-driver##]]). Is this thread-safe?
==== Details ====
I'm writing to ##/fs/dir1/file1## from thread 1, and writing to ##/fs/dir2/file2## from thread 2. The files are in different directories (obviously), but live on the same volume.
I noticed that ChaN's FatFs (which the Mbed OS ##FATFileSystem## wraps) has an [[http://elm-chan.org/fsw/ff/doc/appnote.html#reentrant|##FF_FS_REENTRANT##]] [[http://elm-chan.org/fsw/ff/doc/config.html#fs_reentrant|option]], which Mbed OS doesn't support. Would that be necessary for thread safety?

ChanN's FF_FS_REENTRANT option would allow us to synchronize the filesystem through the ChaN C API, but synchronizing in the C++ layer allows us to directly use the C++ RTOS APIs and use the same locks for the C++ class's state.

Let us know if that helps clear things up.

Hi Brendan,
Yes, the FATFileSystem is thread safe. However, the synchronization is actually implemented in the C++ layer:
https://github.com/ARMmbed/mbed-os/blob/master/features/filesystem/fat/FATFileSystem.cpp#L681-L690
ChanN's FF_FS_REENTRANT option would allow us to synchronize the filesystem through the ChaN C API, but synchronizing in the C++ layer allows us to directly use the C++ RTOS APIs and use the same locks for the C++ class's state.
Let us know if that helps clear things up.

I think it's worth a mention in the documentation, or at least in code comments at the function and/or file level. Do you have an opinion on which is more appropriate? I'm wondering whether to report the issue on mbed-os or the handbook.

Thanks for the info.
I think it's worth a mention in the documentation, or at least in code comments at the function and/or file level. Do you have an opinion on which is more appropriate? I'm wondering whether to report the issue on ##[[https://github.com/ARMmbed/mbed-os/issues|mbed-os]]## or the [[https://github.com/ARMmbed/mbed-os-5-docs/issues|handbook]].
Also, I'll just add this link for future reference to be clear of what you were pointing at, since ##master## is a moving target.
https://github.com/ARMmbed/mbed-os/blob/mbed-os-5.9.3/features/filesystem/fat/FATFileSystem.cpp#L681-L690

Hmm, we could add a note on the functions about thread safety, for example:
https://github.com/ARMmbed/mbed-os/blob/master/drivers/Serial.h#L37
More in depth documentation on why we don't turn on REENTRANT could go in a comment in the ffconf.h.
Both of these would go through [[https://github.com/ARMmbed/mbed-os/issues|mbed-os]].
But an issue in either place would work.

Important Information for this Arm website

This site uses cookies to store information on your computer.
By continuing to use our site, you consent to our cookies.
If you are not happy with the use of these cookies, please review our
Cookie Policy
to learn how they can be disabled.
By disabling cookies, some features of the site will not work.