<?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>Racing adventure in OS</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/81847/racing-adventure-in-os</link><description>Hi,Master: 
 
 Question 1: 
 As shown in the below, why does the api read this variable with critical protection? 
 
 Question 2: 
 Suppose two tasks have write operations to shared variables. For example: 
 
 
 In the OS source code, you can see that</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 18 Nov 2021 12:19:18 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/81847/racing-adventure-in-os" /><item><title>RE: Racing adventure in OS</title><link>https://devzone.nordicsemi.com/thread/339627?ContentTypeID=1</link><pubDate>Thu, 18 Nov 2021 12:19:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c4db6ad0-65e2-4146-abf9-b1576597ed8b</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Regarding Q1, I do not know where this code comes from so I cannot comment on why this is done like it is.&lt;/p&gt;
&lt;p&gt;Regarding Q2, you are right that as this is a pure write (no read-modify-write) there is no need for a critical section here, even if the same variable is written to by two tasks. I cannot see that it serves any purpose. (The variable should be &lt;code&gt;volatile&lt;/code&gt; though (assuming it is also read somewhere), so that the compiler does not optimize away reading of the variable, thinking it know what it is set to.)&lt;/p&gt;
&lt;p&gt;Regarding Q3, there are some situations where you want to use the DSB/ISB instruction but I do not see any particular reason you would need that here (there is no context here, though).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>