<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Littlefs thread safe</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/105004/littlefs-thread-safe</link><description>I&amp;#39;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&amp;#39;m thinking of copying the littlefs_fs.c from</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 20 Dec 2023 10:08:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/105004/littlefs-thread-safe" /><item><title>RE: Littlefs thread safe</title><link>https://devzone.nordicsemi.com/thread/461247?ContentTypeID=1</link><pubDate>Wed, 20 Dec 2023 10:08:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ceed5f1-7ede-4de0-9249-7fa924a6be99</guid><dc:creator>Etienne D.</dc:creator><description>&lt;p&gt;Hello, given your advice to use semaphores at the flash level, are you suggesting that fs operations are generally not thread safe?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;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?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Littlefs thread safe</title><link>https://devzone.nordicsemi.com/thread/452285?ContentTypeID=1</link><pubDate>Wed, 25 Oct 2023 13:26:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aa94c88c-e78b-4da0-a167-c6913e4d5806</guid><dc:creator>SoukTi</dc:creator><description>&lt;p&gt;Thanks. You can mark this once as solved&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Littlefs thread safe</title><link>https://devzone.nordicsemi.com/thread/452232?ContentTypeID=1</link><pubDate>Wed, 25 Oct 2023 10:55:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c5ee38c-a54e-44a1-9b87-dde25048622c</guid><dc:creator>Kenneth</dc:creator><description>[quote user="SoukTi"] so you suggest to do the locks at the user code side[/quote]
&lt;p&gt;Yes, or use work queue.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Littlefs thread safe</title><link>https://devzone.nordicsemi.com/thread/452211?ContentTypeID=1</link><pubDate>Wed, 25 Oct 2023 09:52:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:262b96a1-46cf-4583-9fbc-0eb297f480de</guid><dc:creator>SoukTi</dc:creator><description>&lt;p&gt;Thanks, so you suggest to do the locks at the user code side, not in the ncs littlefs_fs.c file. I will see if its possible to add them there. We have lots of positions in the code that write I&amp;#39;ll need to add lock to each of them.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Littlefs thread safe</title><link>https://devzone.nordicsemi.com/thread/452164?ContentTypeID=1</link><pubDate>Wed, 25 Oct 2023 08:01:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c0df2dbf-5681-45f7-b3ad-a461a2ef6e27</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Depending on who you ask I guess you will get different suggestions, but I am thinking two alternatives, either:&lt;/p&gt;
&lt;p&gt;1. Maybe use work queue to run all flash operation after each other:&lt;br /&gt;&lt;a href="https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/lessons/lesson-7-multithreaded-applications/topic/exercise-3-7/"&gt;https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/lessons/lesson-7-multithreaded-applications/topic/exercise-3-7/&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;2. Use semaphore, e.g. at any time you want to write to flash: take a semaphore, write to flash, release semaphore:&lt;br /&gt;&lt;a href="https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/lessons/lesson-8-thread-synchronization/topic/mutexes/"&gt;https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/lessons/lesson-8-thread-synchronization/topic/mutexes/&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>