Littlefs thread safe

I'm trying to make littlefs thread safe. I have 2 threads, Mcumgr and main that both try to write at the same time which sometimes leads to corrupted filesystem. What is the correct way to accomplish this. I'm thinking of copying the littlefs_fs.c from zephyr and adding the semaphores to this file. 

Is this the best approach, I'm trying to avoid changing the zephyr codebase itself to make changing between nrf connect sdk versions possible. Can you suggest a better way to do this or possibly an existing implementation.

Parents Reply
  • Hello, given your advice to use semaphores at the flash level, are you suggesting that fs operations are generally not thread safe?

    As far as I understand in littlefs_fs.c there is a mutex around the littlefs API calls. So operating on different files from different threads should be fine, right? Only writing to the same file from different threads could lead to issues. Or am I missing something here?

Children
No Data
Related