<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5878854192616837919</id><updated>2024-10-02T09:54:59.345-07:00</updated><title type='text'>Embedded System and Firmware Interview Questions Collection</title><subtitle type='html'>A collection of embedded system and firmware/software interview questions. This blog will help you prepare for your interview efficiently.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>44</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-2771742573958492900</id><published>2011-01-09T01:38:00.003-08:00</published><updated>2011-01-09T01:38:49.139-08:00</updated><title type='text'>Cache Miss</title><content type='html'>&lt;h2 id=&quot;toc0&quot; style=&quot;background: inherit; color: #8f2936; font-family: &#39;Trebuchet MS&#39;, Trebuchet, Verdana, Arial, Helvetica; font-size: 19px; font-weight: normal; font: normal normal normal 150%/normal &#39;Century Gothic&#39;, georgia, Verdana, Arial, Helvetica, sans-serif; padding-left: 1em;&quot;&gt;&lt;span&gt;3 Kinds of Cache Miss&lt;/span&gt;&lt;/h2&gt;&lt;ul style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px;&quot;&gt;&lt;li&gt;Compulsory&lt;/li&gt;
&lt;li&gt;Capacity&lt;/li&gt;
&lt;li&gt;Conflict&lt;/li&gt;
&lt;/ul&gt;&lt;h2 id=&quot;toc1&quot; style=&quot;background: inherit; color: #8f2936; font-family: &#39;Trebuchet MS&#39;, Trebuchet, Verdana, Arial, Helvetica; font-size: 19px; font-weight: normal; font: normal normal normal 150%/normal &#39;Century Gothic&#39;, georgia, Verdana, Arial, Helvetica, sans-serif; padding-left: 1em;&quot;&gt;&lt;span&gt;Reduce Miss Rate&lt;/span&gt;&lt;/h2&gt;&lt;ul style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px;&quot;&gt;&lt;li&gt;Larger Block Size — compulsory&lt;/li&gt;
&lt;li&gt;Higher Associativity — conflict&lt;/li&gt;
&lt;li&gt;Victim Cache — conflict&lt;/li&gt;
&lt;li&gt;HW Prefetching Instruction, Data — compulsory&lt;/li&gt;
&lt;li&gt;SW Prefetching Data — compulsory&lt;/li&gt;
&lt;li&gt;Compiler Optimizations&lt;/li&gt;
&lt;/ul&gt;&lt;h2 id=&quot;toc2&quot; style=&quot;background: inherit; color: #8f2936; font-family: &#39;Trebuchet MS&#39;, Trebuchet, Verdana, Arial, Helvetica; font-size: 19px; font-weight: normal; font: normal normal normal 150%/normal &#39;Century Gothic&#39;, georgia, Verdana, Arial, Helvetica, sans-serif; padding-left: 1em;&quot;&gt;&lt;span&gt;Reduce Miss Penalty&lt;/span&gt;&lt;/h2&gt;&lt;ul style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px;&quot;&gt;&lt;li&gt;Read priority over write on miss&lt;/li&gt;
&lt;li&gt;Early Restart and CriticalWord First on miss&lt;/li&gt;
&lt;li&gt;Non-blocking Caches (Hit Under Miss)&lt;/li&gt;
&lt;li&gt;Multi-level Caches&lt;/li&gt;
&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/2771742573958492900/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/cache-miss.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/2771742573958492900'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/2771742573958492900'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/cache-miss.html' title='Cache Miss'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-1233399003645890356</id><published>2011-01-09T01:38:00.001-08:00</published><updated>2011-01-09T01:38:20.296-08:00</updated><title type='text'>Cache Bus</title><content type='html'>&lt;div style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 1.3em;&quot;&gt;Cache Size is 64KB, Block size is 32B and the cache is Two-Way Set Associative. For a 32-bit physical address, give the division between Block Offset, Index and Tag.&lt;/div&gt;&lt;div style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 1.3em;&quot;&gt;&lt;strong&gt;Number of Blocks:&lt;/strong&gt;&lt;br /&gt;
64k/32 = 2048&lt;br /&gt;
&lt;strong&gt;Index:&lt;/strong&gt;&lt;br /&gt;
2 way set associative — 2000/2 = 1000 lines-&amp;gt; 10 bits for index&lt;br /&gt;
&lt;strong&gt;Block Offset:&lt;/strong&gt;&lt;br /&gt;
32B block -&amp;gt; 5 bits for block offset&lt;br /&gt;
&lt;strong&gt;Tag:&lt;/strong&gt;&lt;br /&gt;
32-10-5= 17 bits for tag&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/1233399003645890356/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/cache-bus.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/1233399003645890356'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/1233399003645890356'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/cache-bus.html' title='Cache Bus'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-9208646605559140775</id><published>2011-01-09T01:37:00.003-08:00</published><updated>2011-01-09T01:37:49.472-08:00</updated><title type='text'>Snooping vs Snarfing</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&lt;strong&gt;Snooping&lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;is the process where the individual caches monitor address lines for accesses to memory locations that they have cached. When a write operation is observed to a location that a cache has a copy of, the cache controller invalidates its own copy of the snooped memory location.&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&lt;strong&gt;Snarfing&lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;is where a cache controller&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&lt;strong&gt;watches both address and data&lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;in an attempt to update its own copy of a memory location&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&lt;strong&gt;when a second master modifies a location in main memory&lt;/strong&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/9208646605559140775/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/snooping-vs-snarfing.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/9208646605559140775'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/9208646605559140775'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/snooping-vs-snarfing.html' title='Snooping vs Snarfing'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-1589212298045992562</id><published>2011-01-09T01:37:00.001-08:00</published><updated>2011-01-09T01:37:18.786-08:00</updated><title type='text'>Write Back vs Write Through</title><content type='html'>&lt;div style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 1.3em;&quot;&gt;&lt;strong&gt;Write-Through cache&lt;/strong&gt;: In this, once the writing is done in the cache memory, the main memory is also updated immediately to maintain the reliability.&lt;br /&gt;
&lt;strong&gt;Write-Back cache&lt;/strong&gt;: In this, once the writing is done in the cache memory,&amp;nbsp;&lt;strong&gt;a flag bit known as dirty bit is set&lt;/strong&gt;. It write the data back to the main memory after a period of time or when the data is swapped out of the cache.&lt;/div&gt;&lt;div style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 1.3em;&quot;&gt;The differences between the Write-through and Write-back cache can be based on two factors (i.e&amp;nbsp;&lt;strong&gt;Performance&lt;/strong&gt;&amp;nbsp;and&amp;nbsp;&lt;strong&gt;Integrity of Data&lt;/strong&gt;). The write-through has a better integrity and it will also flush for each writes. The write-back will hold up the write till the same cache line has to be used up for a read. Thus, write-back will proivde good performance, as it save many memory write cycles&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/1589212298045992562/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/write-back-vs-write-through.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/1589212298045992562'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/1589212298045992562'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/write-back-vs-write-through.html' title='Write Back vs Write Through'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-9188532824285929825</id><published>2011-01-09T01:36:00.003-08:00</published><updated>2011-01-09T01:36:52.574-08:00</updated><title type='text'>Memory Mapped IO vs Port IO</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&lt;strong&gt;Memory-mapped I/O&lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;(MMIO) and&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&lt;strong&gt;port I/O&lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;(also called port-mapped I/O or PMIO) are two complementary methods of performing input/output between the CPU and peripheral devices in a computer.&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&lt;strong&gt;Memory-mapped I/O&lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;(not to be confused with memory-mapped file I/O)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&lt;strong&gt;uses the same address bus to address both memory and I/O devices&lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;, and the CPU instructions used to access the memory are also used for accessing devices. In order to accommodate the I/O devices, areas of the CPU&#39;s addressable space must be reserved for I/O. The reservation might be temporary — the Commodore 64 could bank switch between its I/O devices and regular memory — or permanent. Each&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&lt;strong&gt;I/O device monitors the CPU&#39;s address bus and responds to any of the CPU&#39;s access of device-assigned address space&lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;, connecting the data bus to a desirable device&#39;s hardware register.&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;Port-mapped I/O uses a special class of CPU instructions specifically for performing I/O. This is generally found on Intel microprocessors, specifically the IN and OUT instructions which can read and write one to four bytes (outb, outw, outl) to an I/O device. I/O devices have a separate address space from general memory, either accomplished by an&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&lt;strong&gt;extra &quot;I/O&quot; pin on the CPU&#39;s physical interface&lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;, or an&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&lt;strong&gt;entire bus dedicated to I/O&lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;.&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/9188532824285929825/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/memory-mapped-io-vs-port-io.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/9188532824285929825'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/9188532824285929825'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/memory-mapped-io-vs-port-io.html' title='Memory Mapped IO vs Port IO'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-3391028934638078092</id><published>2011-01-09T01:36:00.001-08:00</published><updated>2011-01-09T01:36:17.145-08:00</updated><title type='text'>DMA</title><content type='html'>&lt;h2 id=&quot;toc0&quot; style=&quot;background: inherit; color: #8f2936; font-family: &#39;Trebuchet MS&#39;, Trebuchet, Verdana, Arial, Helvetica; font-size: 19px; font-weight: normal; font: normal normal normal 150%/normal &#39;Century Gothic&#39;, georgia, Verdana, Arial, Helvetica, sans-serif; padding-left: 1em;&quot;&gt;&lt;span&gt;DMA Advantage&lt;/span&gt;&lt;/h2&gt;&lt;div style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 1.3em;&quot;&gt;DMA is a hardware device that helps the data transmission between hardware device and memory. Computers that have DMA can transfer data to and from devices with much less CPU overhead than computers without a DMA.&lt;/div&gt;&lt;div style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 1.3em;&quot;&gt;Without DMA, using programmed input/output (PIO) mode for communication with peripheral devices , or load/store instructions in the case of multicore chips(&lt;strong&gt;with polled waiting loop or interrupt driven IO&lt;/strong&gt;), the CPU is typically fully occupied for the entire duration of the read or write operation, and is thus unavailable to perform other work. With DMA,&amp;nbsp;&lt;strong&gt;the CPU would initiate the transfer, do other operations while the transfer is in progress, and receive an interrupt from the DMA controller once the operation has been done&lt;/strong&gt;. This is especially useful in real-time computing applications where not stalling behind concurrent operations is critical. Another and related application area is various forms of stream processing where it is essential to have data processing and transfer in parallel, in order to achieve sufficient throughput.&lt;/div&gt;&lt;h2 id=&quot;toc1&quot; style=&quot;background: inherit; color: #8f2936; font-family: &#39;Trebuchet MS&#39;, Trebuchet, Verdana, Arial, Helvetica; font-size: 19px; font-weight: normal; font: normal normal normal 150%/normal &#39;Century Gothic&#39;, georgia, Verdana, Arial, Helvetica, sans-serif; padding-left: 1em;&quot;&gt;&lt;span&gt;Single Mode &amp;amp; Burst Mode&lt;/span&gt;&lt;/h2&gt;&lt;div style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 1.3em;&quot;&gt;&lt;strong&gt;Traditional Synchronous DMA&lt;/strong&gt;&amp;nbsp;moves a byte or word at a time between system memory and a peripheral, handshaking with the I/O port for each transfer. This sort of transfer recognizes that the port may not always be in a ready condition; the handshaking is a hardware mechanism to throttle the transactions.&lt;/div&gt;&lt;div style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 1.3em;&quot;&gt;With this sort of transfer, the program sets up the controller and then carries on, oblivious to the state of the DMA transaction. The hardware moves one byte or word between memory and I/O each time the I/O port signals it is ready for another transaction. On each read indication, the DMA controller asserts Bus Request, waits for a Bus Acknowledge in response, and then takes over the bus for a single cycle. Then, the DMA controller goes idle again, waiting for another ready signal from the port. Thus, the program and DMA cycles share bus cycles, with the controller winning any contest for control of the bus. Sometimes this is called &quot;Cycle Stealing&quot;.&lt;/div&gt;&lt;div style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 1.3em;&quot;&gt;&lt;strong&gt;Burst Mode DMA&lt;/strong&gt;, in contrast, generally assumes that the destination and source addresses can take transfers as fast as the controller can generate them. The program sets up the controller, and then (perhaps after a single ready indication from a port occurs), the entire source block is copied to the destination. The DMA controller gains exclusive access to the bus for the duration of the transfer, during which time the program is effectively shut down. Burst mode DMA can transfer data very rapidly indeed.&lt;/div&gt;&lt;h2 id=&quot;toc2&quot; style=&quot;background: inherit; color: #8f2936; font-family: &#39;Trebuchet MS&#39;, Trebuchet, Verdana, Arial, Helvetica; font-size: 19px; font-weight: normal; font: normal normal normal 150%/normal &#39;Century Gothic&#39;, georgia, Verdana, Arial, Helvetica, sans-serif; padding-left: 1em;&quot;&gt;&lt;span&gt;Reference&lt;/span&gt;&lt;/h2&gt;&lt;div style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 1.3em;&quot;&gt;&lt;a href=&quot;http://www.ganssle.com/articles/adma.htm&quot; style=&quot;background: inherit; color: #3c52be; text-decoration: none;&quot;&gt;http://www.ganssle.com/articles/adma.htm&lt;/a&gt;&amp;nbsp;— Good DMA article&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/3391028934638078092/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/dma.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/3391028934638078092'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/3391028934638078092'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/dma.html' title='DMA'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-668359673110183614</id><published>2011-01-09T01:35:00.001-08:00</published><updated>2011-01-09T01:35:46.269-08:00</updated><title type='text'>RISC vs CISC</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;The major difference is that RISC has fewer number of instructions and each of them performs simpler function, has simpler format, and most instructions have the same number of clock cycles, so we can apply pipeline technique to improve performance. On the other hand, CISC processors have a large amount of different, complex instructions, and each of them may require various number of clock cycles and contain various number of bits. RISC processor has better performance, but CISC processor can has code which has much less lines than RISC processor. Moreover, CISC typically requires more hardware resource to support its powerful instructions, therefore also has higher power consumption. For example, CISC may has a dedicated hardware for multiplication, while RISC may combine shift and add instruction to achieve multiplication.&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/668359673110183614/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/risc-vs-cisc.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/668359673110183614'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/668359673110183614'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/risc-vs-cisc.html' title='RISC vs CISC'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-5081534673606085067</id><published>2011-01-09T01:33:00.001-08:00</published><updated>2011-01-09T01:33:45.090-08:00</updated><title type='text'>Pipeline</title><content type='html'>&lt;h3 id=&quot;toc0&quot; style=&quot;background: inherit; color: #4e6241; font-family: &#39;Trebuchet MS&#39;, Trebuchet, Verdana, Arial, Helvetica; font-size: 17px; font-weight: bold; font: normal normal normal 130%/normal &#39;Century Gothic&#39;, georgia, Verdana, Arial, Helvetica, sans-serif; margin-bottom: 0px; margin-left: 32px; margin-right: 0px; margin-top: 36px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&lt;span&gt;Multiple Cycle CPU&lt;/span&gt;&lt;/h3&gt;&lt;div style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 1.3em;&quot;&gt;as its name implies, the multiple cycle cpu requires multiple cycles to execute a single instruction. this means that our cpi will be greater than 1.&lt;/div&gt;&lt;div style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 1.3em;&quot;&gt;the big&amp;nbsp;&lt;strong&gt;advantage&lt;/strong&gt;&amp;nbsp;of the multi-cycle design is that&amp;nbsp;&lt;strong&gt;we can use more or less cycles to execute each instruction, depending on the complexity of the instruction&lt;/strong&gt;. for example, we can take five cycles to execute a load instruction, but we can take just three cycles to execute a branch instruction. the big&amp;nbsp;&lt;strong&gt;disadvantage&lt;/strong&gt;&amp;nbsp;of the multi-cycle design is increased&amp;nbsp;&lt;strong&gt;complexity&lt;/strong&gt;. control is now a finite state machine - before it was just combinational logic.&lt;/div&gt;&lt;div style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 1.3em;&quot;&gt;another important difference between the single-cycle design and the multi-cycle design is the cycle time. in the&amp;nbsp;&lt;strong&gt;single cycle processor, the cycle time was determined by the slowest instruction. in the multi-cycle design, the cycle time is determined by the slowest functional unit [memory, registers, alu]&lt;/strong&gt;. this greatly reduces our cycle time.&lt;/div&gt;&lt;h3 id=&quot;toc1&quot; style=&quot;background: inherit; color: #4e6241; font-family: &#39;Trebuchet MS&#39;, Trebuchet, Verdana, Arial, Helvetica; font-size: 17px; font-weight: bold; font: normal normal normal 130%/normal &#39;Century Gothic&#39;, georgia, Verdana, Arial, Helvetica, sans-serif; margin-bottom: 0px; margin-left: 32px; margin-right: 0px; margin-top: 36px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&lt;span&gt;Outline&lt;/span&gt;&lt;/h3&gt;&lt;div style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 1.3em;&quot;&gt;this outline describes all the things that happen on various cycles in our multi-cycle cpu. all the events described in each numbered item take place in one clock cycle.&lt;/div&gt;&lt;div style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 1.3em;&quot;&gt;&lt;strong&gt;1) instruction fetch&lt;/strong&gt;: load ir with instruction at pc, load pc with pc + 4. If its not a branch instruction, pc+4 will be used to fetch instruction in the next clock cycle. If its a branch instruction, taken or non-taken will be resolved after after 2 clock cycles (after ALU). At the 3th cycle, pc+4 or branch address will be selected to fetch the instruction.&lt;br /&gt;
&lt;strong&gt;2) instruction decode, read registers&lt;/strong&gt;: parse the instruction, load registers A and B with values from the register file, load aluout with the target address of the branch&lt;br /&gt;
&lt;strong&gt;3) execute&lt;/strong&gt;: if executing a load or store, perform the effective address computation and put the result in aluout. for arithmetic instructions, load aluout with the result of the appropriate computation. for a beq instruction, if the result of register A is zero, load pc with the value in aluout. if executing a beq, we are done - return to step 1&lt;br /&gt;
&lt;strong&gt;4) memory&lt;/strong&gt;: if executing a load, load mdr with the data at address aluout. if executing a store, write the data in register b into memory at address aluout. if executing an arithmetic instruction, write the value in aluout into the register file. if executing a store or an arithmetic instruction, we are done - return to step 1&lt;br /&gt;
&lt;strong&gt;5) writeback&lt;/strong&gt;: if we are here, we are executing a load instruction. write the value in mdr into the register file, and return to step 1&lt;/div&gt;&lt;h3 id=&quot;toc2&quot; style=&quot;background: inherit; color: #4e6241; font-family: &#39;Trebuchet MS&#39;, Trebuchet, Verdana, Arial, Helvetica; font-size: 17px; font-weight: bold; font: normal normal normal 130%/normal &#39;Century Gothic&#39;, georgia, Verdana, Arial, Helvetica, sans-serif; margin-bottom: 0px; margin-left: 32px; margin-right: 0px; margin-top: 36px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&lt;span&gt;Pipeline Performance&lt;/span&gt;&lt;/h3&gt;&lt;div style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 1.3em;&quot;&gt;Ideally, for an n stages pipeline, the performance improvement is&amp;nbsp;&lt;strong&gt;n times&lt;/strong&gt;&amp;nbsp;than non-pipeline structure. However, mostly it can not be achieved, because:&lt;br /&gt;
1)&amp;nbsp;&lt;strong&gt;uneven pipeline stages&lt;/strong&gt;: we can hardly separate task to stages with the same execution time.&lt;br /&gt;
2)&amp;nbsp;&lt;strong&gt;hazards&lt;/strong&gt;: so we can&#39;t always let the pipeline full.&lt;br /&gt;
3) latch overhead&lt;/div&gt;&lt;h2 id=&quot;toc3&quot; style=&quot;background: inherit; color: #8f2936; font-family: &#39;Trebuchet MS&#39;, Trebuchet, Verdana, Arial, Helvetica; font-size: 19px; font-weight: normal; font: normal normal normal 150%/normal &#39;Century Gothic&#39;, georgia, Verdana, Arial, Helvetica, sans-serif; padding-left: 1em;&quot;&gt;&lt;span&gt;Reference&lt;/span&gt;&lt;/h2&gt;&lt;div style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 1.3em;&quot;&gt;&lt;a href=&quot;http://www.cs.umass.edu/~weems/CmpSci535/Discussion14.html&quot; style=&quot;background: inherit; color: #3c52be; text-decoration: none;&quot;&gt;http://www.cs.umass.edu/~weems/CmpSci535/Discussion14.html&lt;/a&gt;&amp;nbsp;— instruction fetch&lt;br /&gt;
&lt;a href=&quot;http://cseweb.ucsd.edu/~j2lau/cs141/week4.html&quot; style=&quot;background: inherit; color: #3c52be; text-decoration: none;&quot;&gt;http://cseweb.ucsd.edu/~j2lau/cs141/week4.html&lt;/a&gt;&amp;nbsp;— pipeline &amp;amp; multiple cycle&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/5081534673606085067/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/pipeline.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/5081534673606085067'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/5081534673606085067'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/pipeline.html' title='Pipeline'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-6413547144992907989</id><published>2011-01-09T01:31:00.001-08:00</published><updated>2011-01-09T01:32:56.360-08:00</updated><title type='text'>Hazards</title><content type='html'>&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;A hazard is a potential problem that can cause a pipelined processor to obtain incorrect computing result. There are typically three types of hazards: data hazards, structural hazards, and branching hazards (control hazards).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;h3 id=&quot;toc0&quot; style=&quot;background: inherit; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 24.0pt; margin-right: 0cm; margin-top: 27.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #4e6241; font-family: &#39;Century Gothic&#39;, sans-serif; font-size: 13pt; font-weight: normal; line-height: 300%;&quot;&gt;Data Hazard&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Data hazard can happen when a CPU tries to simultaneously execute multiple instructions which exhibit data dependence&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;h5 id=&quot;toc1&quot; style=&quot;margin-left: 24.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;RAW - Read After Write&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 10pt; line-height: 300%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h5&gt;&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;A RAW Data Hazard refers to a situation where we refer to a result that has not yet been calculated, for example:&lt;br /&gt;
i1. R2 &amp;lt;- R1 + R3&lt;br /&gt;
i2. R4 &amp;lt;- R2 + R3&lt;br /&gt;
The first instruction is calculating a value to be saved in register 2, and the second is going to use this value to compute a result for register 4. However, in a pipeline, when we fetch the operands for the 2nd operation, the results from the first will not yet have been saved, and hence we have a data dependency.&lt;br /&gt;
We say that there is a data dependency with instruction 2, as it is dependent on the completion of instruction 1.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;h5 id=&quot;toc2&quot; style=&quot;margin-left: 24.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;WAR - Write After Read&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 10pt; line-height: 300%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h5&gt;&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;A WAR Data Hazard represents a problem with concurrent execution, for example:&lt;br /&gt;
i1. R4 &amp;lt;- R1 + R3&lt;br /&gt;
i2. R3 &amp;lt;- R1 + R2&lt;br /&gt;
If we are in a situation that there is a chance that i2 may be completed before i1 (i.e. with concurrent execution) we must ensure that we do not store the result of register 3 before i1 has had a chance to fetch the operands.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;h5 id=&quot;toc3&quot; style=&quot;margin-left: 24.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;WAW - Write After Write&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 10pt; line-height: 300%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h5&gt;&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;A WAW Data Hazard is another situation which may occur in a concurrent execution environment, for example:&lt;br /&gt;
i1. R2 &amp;lt;- R1 + R2&lt;br /&gt;
i2. R2 &amp;lt;- R4 + R7&lt;br /&gt;
We must delay the WB (Write Back) of i2 until the execution of i1.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;h5 id=&quot;toc4&quot; style=&quot;margin-left: 24.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #38761d; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: small; font-weight: normal;&quot;&gt;Solutions&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 10pt; line-height: 300%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h5&gt;&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;strong&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;1) data forwarding:&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;some data hazards can&#39;t be solved by it. Ex. lw instruction in MIPS architecture&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;2) pipeline stall&lt;/span&gt;&lt;/strong&gt;: Ex. for lw instruction&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;3) instruction scheduling&lt;/span&gt;&lt;/strong&gt;:&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Compiler should do that.&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;Ex.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;lw R1, 1000(R2)&lt;br /&gt;
lw R3, 2000(R2)&lt;br /&gt;
&lt;em&gt;&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;add R4, R1, R3&lt;/span&gt;&lt;/b&gt;&lt;/em&gt;&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;lw R1, 3000(R2)&lt;/span&gt;&lt;/em&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
add R6, R4, R1&lt;br /&gt;
sw R6, 1000(R2)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;change to&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;lw R1, 1000(R2)&lt;br /&gt;
lw R3, 2000(R2)&lt;br /&gt;
&lt;em&gt;&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;lw Rn, 3000(R2) // swap &quot;lw&quot; and &quot;add&quot;&lt;/span&gt;&lt;/b&gt;&lt;/em&gt;&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;add R4, R1, R3&lt;/span&gt;&lt;/em&gt;&lt;/i&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;add R6, R4, Rn&lt;/span&gt;&lt;/strong&gt;&lt;/b&gt;&lt;br /&gt;
sw R6, 1000(R2)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;h3 id=&quot;toc5&quot; style=&quot;background: inherit; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 24.0pt; margin-right: 0cm; margin-top: 27.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #4e6241; font-family: &#39;Century Gothic&#39;, sans-serif; font-size: 13pt; font-weight: normal; line-height: 300%;&quot;&gt;Structural Hazard&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;A structural hazard occurs when a part of the processor&#39;s hardware is needed by two or more instructions at the same time. A structural hazard might occur, for instance, if a program were to execute a branch instruction followed by a computation instruction. Because they are executed in parallel, and because branching is typically slow (requiring a comparison, program counter-related computation, and writing to registers), it is quite possible (depending on architecture) that the computation instruction and the branch instruction will both require the ALU (arithmetic logic unit) at the same time.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;h3 id=&quot;toc6&quot; style=&quot;background: inherit; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 24.0pt; margin-right: 0cm; margin-top: 27.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #4e6241; font-family: &#39;Century Gothic&#39;, sans-serif; font-size: 13pt; font-weight: normal; line-height: 300%;&quot;&gt;Branch Harzard&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Branching hazards (also known as control hazards) occur when the processor is told to branch - i.e., if a certain condition is true, then jump from one part of the instruction stream to another - not necessarily to the next instruction sequentially. In such a case, the processor cannot tell in advance whether it should process the next instruction (when it may instead have to move to a distant instruction).&lt;br /&gt;
This can result in the processor doing unwanted actions.&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;1) stall pipeline:&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;until we know its taken or non-taken&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;2) predict taken or non-taken:&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;and fill the pipeline with associated instruction. Compiler uses&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;like taken&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;and&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;unlikely taken&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;to denote the branch instruction, and if its found not the case, CPU&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;cancel or nullify the delayed slot instruction&lt;/span&gt;&lt;/strong&gt;.&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;3) delayed branch:&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;Fill instruction that will be valid no matter branch is taken or non-taken into pipeline.&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Compiler should do that.&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;4) hardware branch predictor:&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;Its dynamic branch prediction. static branch prediction is done by compiler.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;h1 id=&quot;toc7&quot; style=&quot;background: inherit;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &#39;Century Gothic&#39;, sans-serif; font-size: 25pt; font-weight: normal;&quot;&gt;Reference&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h1&gt;&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Hazard_(computer_architecture&quot; style=&quot;background: inherit;&quot;&gt;&lt;span style=&quot;color: #3c52be; text-decoration: none;&quot;&gt;http://en.wikipedia.org/wiki/Hazard_(computer_architecture&lt;/span&gt;&lt;/a&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/6413547144992907989/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/hazards.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/6413547144992907989'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/6413547144992907989'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/hazards.html' title='Hazards'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-7301293418646730257</id><published>2011-01-09T01:30:00.000-08:00</published><updated>2011-01-09T01:30:31.809-08:00</updated><title type='text'>Harvard Vs Von Neuman</title><content type='html'>&lt;h2 id=&quot;toc0&quot; style=&quot;background: inherit; color: #8f2936; font-family: &#39;Trebuchet MS&#39;, Trebuchet, Verdana, Arial, Helvetica; font-size: 19px; font-weight: normal; font: normal normal normal 150%/normal &#39;Century Gothic&#39;, georgia, Verdana, Arial, Helvetica, sans-serif; padding-left: 1em;&quot;&gt;&lt;span&gt;Difference&lt;/span&gt;&lt;/h2&gt;&lt;div style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 1.3em;&quot;&gt;With a Harvard architecture, there are&amp;nbsp;&lt;strong&gt;two separate memory space&lt;/strong&gt;, one for instruction and one for data. We can increase the throughput because when we are executing one instruction, we can be fetching the next instruction. Other advantage is that, we can have different width on instruction bus and data bus.&lt;/div&gt;&lt;h2 id=&quot;toc1&quot; style=&quot;background: inherit; color: #8f2936; font-family: &#39;Trebuchet MS&#39;, Trebuchet, Verdana, Arial, Helvetica; font-size: 19px; font-weight: normal; font: normal normal normal 150%/normal &#39;Century Gothic&#39;, georgia, Verdana, Arial, Helvetica, sans-serif; padding-left: 1em;&quot;&gt;&lt;span&gt;Reference&lt;/span&gt;&lt;/h2&gt;&lt;div style=&quot;color: #333333; font-family: Verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 1.3em;&quot;&gt;&lt;a href=&quot;http://www.pictutorials.com/Harvard_vs_Von_Nuemann_Architecture.htm&quot; style=&quot;background: inherit; color: #3c52be; text-decoration: none;&quot;&gt;http://www.pictutorials.com/Harvard_vs_Von_Nuemann_Architecture.htm&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/7301293418646730257/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/harvard-vs-von-neuman.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/7301293418646730257'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/7301293418646730257'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/harvard-vs-von-neuman.html' title='Harvard Vs Von Neuman'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-3444896499383836637</id><published>2011-01-09T01:26:00.001-08:00</published><updated>2011-01-09T01:26:37.586-08:00</updated><title type='text'>Reentrant Function</title><content type='html'>&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-outline-level: 2; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &amp;quot;Century Gothic&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 15.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Definition&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 15.6pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;A&amp;nbsp;&lt;/span&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;reentrant function&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&amp;nbsp;is one that can be used by more than one task concurrently without fear of data corruption. Conversely, a&amp;nbsp;&lt;/span&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;non-reentrant&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&amp;nbsp;function is one that cannot be shared by more than one task&amp;nbsp;&lt;/span&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;unless mutual exclusion to the function is ensured&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&amp;nbsp;either by using a semaphore or by disabling interrupts during critical sections of code. A reentrant function can be interrupted at any time and resumed at a later time without loss of data. Reentrant functions either use local variables or protect their data when global variables are used.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 15.6pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;A reentrant function:&lt;br /&gt;
1) Does not hold static data over successive calls&lt;br /&gt;
2)&amp;nbsp;&lt;/span&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Does not return a pointer to static data&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;; all data is provided by the caller of the function&lt;br /&gt;
3) Uses local data or&amp;nbsp;&lt;/span&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;ensures protection of global data by making a local copy of it&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;br /&gt;
4)&amp;nbsp;&lt;/span&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Must not call any non-reentrant functions&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-outline-level: 2; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &amp;quot;Century Gothic&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 15.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Floating Point Reentrant for Keil C51&amp;nbsp;C compiler&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 15.6pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Floating point operations the compiler generates code for (+ - * /) are fully reentrant. But only a few functions in math.h are reentrant.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 15.6pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Those that are not reentrant must be protected from interrupts. One way this can be accomplished is to put a wrapper that disables and re-enables interrupts around the floating point math calls. For example:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;#pragma&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt; disable&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #449944; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;// Disable Interrupts for this function&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;float&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt; ISR_sin (&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;float&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt; x)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #5555dd; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;return&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt; (sin(x));&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;}&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-outline-level: 2; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &amp;quot;Century Gothic&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 15.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Examples&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;void&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt; func(&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;int&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;* x, &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;int&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;* y) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;{ &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;int&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt; tmp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;tmp=*x; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;*x=*y; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;*y=tmp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;}&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;the above is reentrant or not?&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Reentrant&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: 新細明體; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-outline-level: 2; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &amp;quot;Century Gothic&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 15.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Non-Reentrant to Reentrant&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &amp;quot;Century Gothic&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 15.0pt; mso-bidi-font-family: 新細明體; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 15.6pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Non-reentrant version&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;char&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;* FileName(&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;char&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt; *name)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;static&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt; &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;char&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt; fname[&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: maroon; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;13&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;sprintf(fname, &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #000099; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&quot;%s&quot;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;, name);&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #449944; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;// can&#39;t write fname = name&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #5555dd; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;return&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt; fname;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;}&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 15.6pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Reentrant versions&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;char&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;* FileName1(&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;char&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt; *name, &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;char&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt; *fname_buf)&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #449944; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;// use thread&#39;s own buffer&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;sprintf(fname_buf, &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #000099; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&quot;%s&quot;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;, name);&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #449944; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;// can write fname_buf = name&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #5555dd; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;return&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt; fname_buf;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;char&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;* FileName2(&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;char&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt; *name)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;char&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt; *fname_buf = (&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;char&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;*)malloc(&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: maroon; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;13&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;);&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #449944; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;// malloc will allocate memory every call&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;sprintf(fname_buf, &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #000099; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&quot;%s&quot;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;, name);&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #449944; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;// can write fname_buf = name&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #5555dd; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;return&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt; fname_buf;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;}&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;The first one better, because second requires free() to release memory, and takes longer time to allocate memory.&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/3444896499383836637/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/reentrant-function.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/3444896499383836637'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/3444896499383836637'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/reentrant-function.html' title='Reentrant Function'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-7799284671503017784</id><published>2011-01-09T01:24:00.001-08:00</published><updated>2011-01-09T01:25:53.105-08:00</updated><title type='text'>Inter Process Communication</title><content type='html'>&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;strong&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Advantages of process cooperation&lt;/span&gt;&lt;/strong&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul type=&quot;disc&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l1 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Information sharing&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l1 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Computation speed-up&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l1 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Modularity&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l1 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Convenience&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;strong&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Disadvantage of process cooperation&lt;/span&gt;&lt;/strong&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul type=&quot;disc&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l3 level1 lfo2; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Data corruption, deadlocks, increased      complexity&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l3 level1 lfo2; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Requires processes to synchronize their      processing&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h2 id=&quot;toc1&quot; style=&quot;background: inherit;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &#39;Century Gothic&#39;, sans-serif; font-size: 15pt; font-weight: normal;&quot;&gt;Event Flags&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;a href=&quot;http://www.ecoscentric.com/ecospro/doc.cgi/html/ref/kernel-flags.html&quot; style=&quot;background: inherit;&quot;&gt;&lt;span style=&quot;color: #3c52be;&quot;&gt;http://www.ecoscentric.com/ecospro/doc.cgi/html/ref/kernel-flags.html&lt;/span&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;h2 id=&quot;toc2&quot; style=&quot;background: inherit;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &#39;Century Gothic&#39;, sans-serif; font-size: 15pt; font-weight: normal;&quot;&gt;Shared Memory&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;If&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;threads are in different process&lt;/span&gt;&lt;/strong&gt;, we need to request a segment of shared memory from kernel, and processes communicate through this shared memory by reading and writing data on it.&lt;br /&gt;
If&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;threads are in the same process&lt;/span&gt;&lt;/strong&gt;, there are several types of shared memory:&lt;br /&gt;
1)&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Shared global variable&lt;/span&gt;&lt;/strong&gt;: global variables within source code of multiple threads.&lt;br /&gt;
2)&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Shared private data&lt;/span&gt;&lt;/strong&gt;: private variables whose address are given to other threads.&lt;br /&gt;
3)&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Static variable&lt;/span&gt;&lt;/strong&gt;: all static variables within a shared function will become shared data. All functions which are called in a shared function are also shared functions.&lt;br /&gt;
With shared memory,&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;synchronization should be achieved by processes/threads&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;themselves to avoid data corruption.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;h2 id=&quot;toc3&quot; style=&quot;background: inherit;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &#39;Century Gothic&#39;, sans-serif; font-size: 15pt; font-weight: normal;&quot;&gt;Message Passing&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;In message passing, there is&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;no shared memory&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;between processes. Using kernel function, kernel will copy data from the source process to kernel space, and then copy the data from kernel space to destination process. There are basically two operations,&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;send(pid, message)&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;and&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;receive(pid, message)&lt;/span&gt;&lt;/strong&gt;. Synchronization and data protection are handled by kernel.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;h5 id=&quot;toc4&quot; style=&quot;margin-left: 24.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;Blocking &amp;amp; Non-Blocking&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 10pt; line-height: 300%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h5&gt;&lt;ul type=&quot;disc&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l2 level1 lfo3; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Blocking Send — sender blocked until message      received by mailbox or process&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l2 level1 lfo3; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Nonblocking Send — sender resumes operation      immediately after sending&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l2 level1 lfo3; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Blocking Receive — receiver blocks until a      message is available&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l2 level1 lfo3; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Nonblocking Receive — receiver returns      immediately with either a valid or null message.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h5 id=&quot;toc5&quot; style=&quot;margin-left: 24.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;Buffering&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: 10pt; line-height: 300%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h5&gt;&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;All messaging system require framework to temporarily buffer messages. These queues are implemented in one of three ways:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul type=&quot;disc&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l0 level1 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Zero Capacity — No messages may be queued      within the link, requires sender to block until receives retrieves      message.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l0 level1 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Bounded Capacity — Link has finite number of      message buffers. If no buffers are available(buffer is full) then sender      must block until one is freed up.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l0 level1 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Unbounded Capacity — Link has unlimited buffer      space, consequently send never needs to block. It can be approximated by linked      list, while it still has a boundary (when heap section is full).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/7799284671503017784/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/inter-process-communication.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/7799284671503017784'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/7799284671503017784'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/inter-process-communication.html' title='Inter Process Communication'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-4472541582080928011</id><published>2011-01-09T01:22:00.001-08:00</published><updated>2011-01-09T01:22:48.419-08:00</updated><title type='text'>Polled Waiting vs Interrupt Driven</title><content type='html'>&lt;div style=&quot;background: #FAFAFA; line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial;&quot;&gt;Real-time systems are said to be “&lt;strong&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-bidi-font-family: Arial;&quot;&gt;event-driven&lt;/span&gt;&lt;/strong&gt;”, meaning that a primary function of the system is to respond to “events” that occur in the system’s environment. How does the program detect an event happening? There are two fundamental approaches:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;h2 id=&quot;toc0&quot; style=&quot;background: #FAFAFA inherit;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &amp;quot;Century Gothic&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 15.0pt; font-weight: normal; mso-bidi-font-family: Arial;&quot;&gt;Polled Waiting&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div style=&quot;background: #FAFAFA; line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial;&quot;&gt;The program begins with some&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-bidi-font-family: Arial;&quot;&gt;initialization&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;and then&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-bidi-font-family: Arial;&quot;&gt;enters an infinite loop&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;that tests each possible event to which the system must respond. For each event that is set, the program invokes the appropriate servicing function.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-types&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;int&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;main&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-types&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;sys_init&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #5555dd; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;while&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;TRUE&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #5555dd; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;event_1&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;service_event_1&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #5555dd; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;event_2&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;service_event_2&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-comment&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #449944; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;// ........&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #5555dd; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;event_n&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;service_event_n&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;h3 id=&quot;toc1&quot; style=&quot;background: #FAFAFA inherit; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 24.0pt; margin-right: 0cm; margin-top: 27.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #4e6241; font-family: &amp;quot;Century Gothic&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; font-weight: normal; line-height: 300%; mso-bidi-font-family: Arial;&quot;&gt;When to use&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;ul type=&quot;disc&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;background: #FAFAFA; color: #333333; mso-list: l2 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;strong&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial;&quot;&gt;Fast device&lt;/span&gt;&lt;/strong&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial;&quot;&gt;: for devices which input or output data in      very fast speed, it&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-bidi-font-family: Arial;&quot;&gt;won&#39;t      execute useless loops for many times&lt;/span&gt;&lt;/strong&gt;, so won&#39;t introduce      much overhead. However, if we use interrupt driven IO, the overall      overhead generated by dealing with interrupts may be very high.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;background: #FAFAFA; color: #333333; mso-list: l2 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;strong&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial;&quot;&gt;Periodic      device&lt;/span&gt;&lt;/strong&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial;&quot;&gt;: we can let the task      which run the polled waiting loop sleep for a period of time, and wake up      it when the data is about ready.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h3 id=&quot;toc2&quot; style=&quot;background: #FAFAFA inherit; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 24.0pt; margin-right: 0cm; margin-top: 27.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #4e6241; font-family: &amp;quot;Century Gothic&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; font-weight: normal; line-height: 300%; mso-bidi-font-family: Arial;&quot;&gt;Disadvantage&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;ul type=&quot;disc&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;background: #FAFAFA; color: #333333; mso-list: l0 level1 lfo2; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial;&quot;&gt;The&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-bidi-font-family: Arial;&quot;&gt;response time to an      event varies&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;widely      depending on where in the loop the program is when the event occurs. For      example, if event_1 occurs immediately before the if (event_1) statement      is executed, the response time is very short. However if it occurs      immediately after the test, the program must go through the entire loop      before servicing event_1.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;background: #FAFAFA; color: #333333; mso-list: l0 level1 lfo2; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial;&quot;&gt;For slow device,      introduce huge&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-bidi-font-family: Arial;&quot;&gt;overhead      because of busy waiting&lt;/span&gt;&lt;/strong&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;background: #FAFAFA; color: #333333; mso-list: l0 level1 lfo2; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial;&quot;&gt;All events are treated      as having&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-bidi-font-family: Arial;&quot;&gt;equal      priority&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;(If      all event are tested in the same process).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;background: #FAFAFA; color: #333333; mso-list: l0 level1 lfo2; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial;&quot;&gt;As new features, hence&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-bidi-font-family: Arial;&quot;&gt;new events are added&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;to the system, the&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-bidi-font-family: Arial;&quot;&gt;loop gets longer&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;and so does the response time.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;background: #FAFAFA; color: #333333; mso-list: l0 level1 lfo2; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial;&quot;&gt;The response time is      also a function of how many events happen to be set at the same time and      consequently get serviced in the same pass through the loop.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h2 id=&quot;toc3&quot; style=&quot;background: #FAFAFA inherit;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &amp;quot;Century Gothic&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 15.0pt; font-weight: normal; mso-bidi-font-family: Arial;&quot;&gt;Interrupt Driven&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h2&gt;&lt;h3 id=&quot;toc4&quot; style=&quot;background: #FAFAFA inherit; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 24.0pt; margin-right: 0cm; margin-top: 27.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #4e6241; font-family: &amp;quot;Century Gothic&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; font-weight: normal; line-height: 300%; mso-bidi-font-family: Arial;&quot;&gt;When to use&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;ul type=&quot;disc&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;background: #FAFAFA; color: #333333; mso-list: l3 level1 lfo3; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;strong&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial;&quot;&gt;Slow and      Non-periodic device&lt;/span&gt;&lt;/strong&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial;&quot;&gt;: for this      kind of device, interrupt driven IO can achieve much higher performance      than polled waiting.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;background: #FAFAFA; color: #333333; mso-list: l3 level1 lfo3; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;strong&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial;&quot;&gt;Device      requires guaranteed short latency&lt;/span&gt;&lt;/strong&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial;&quot;&gt;: since polled waiting IO introduce various latency.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h3 id=&quot;toc5&quot; style=&quot;background: #FAFAFA inherit; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 24.0pt; margin-right: 0cm; margin-top: 27.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #4e6241; font-family: &amp;quot;Century Gothic&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; font-weight: normal; line-height: 300%; mso-bidi-font-family: Arial;&quot;&gt;Disadvantage&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;ul type=&quot;disc&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;background: #FAFAFA; color: #333333; mso-list: l1 level1 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial;&quot;&gt;It has&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-bidi-font-family: Arial;&quot;&gt;large overhead/byte,      therefore low transfer rate&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;when transmits one or few bytes      of data per interrupt. It needs to 1. push program counter, flag register.      2. read interrupt type code, access interrupt vector table, load address      of ISR. 3. after that, it might need to push values of all register that      will be used in the ISR. 4. when the ISR return, CPU need to restore it      previous status by popping values from stack to registers.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;background: #FAFAFA; color: #333333; mso-list: l1 level1 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial;&quot;&gt;According to the above      reason, for device which has&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-bidi-font-family: Arial;&quot;&gt;high      speed&lt;/span&gt;&lt;/strong&gt;, the&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-bidi-font-family: Arial;&quot;&gt;overhead&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;introduced by interrupt driven IO      will be significant.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;background: #FAFAFA; color: #333333; mso-list: l1 level1 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial;&quot;&gt;Increase&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-bidi-font-family: Arial;&quot;&gt;complexity&lt;/span&gt;&lt;/strong&gt;,      and introduce problem of synchronization.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h2 id=&quot;toc6&quot; style=&quot;background: #FAFAFA inherit;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &amp;quot;Century Gothic&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 15.0pt; font-weight: normal; mso-bidi-font-family: Arial;&quot;&gt;Reference&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div style=&quot;background: #FAFAFA; line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial;&quot;&gt;&lt;a href=&quot;http://0rz.tw/iRpLY&quot; style=&quot;background: inherit;&quot;&gt;&lt;span style=&quot;color: #3c52be; text-decoration: none; text-underline: none;&quot;&gt;http://0rz.tw/iRpLY&lt;/span&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/4472541582080928011/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/polled-waiting-vs-interrupt-driven.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/4472541582080928011'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/4472541582080928011'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/polled-waiting-vs-interrupt-driven.html' title='Polled Waiting vs Interrupt Driven'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-599500738068244164</id><published>2011-01-09T01:19:00.000-08:00</published><updated>2011-01-10T22:13:32.103-08:00</updated><title type='text'>Multi Tasking or Multi Thread</title><content type='html'>&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif;&quot;&gt;In embedded system, process and thread are often called&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;task&lt;/span&gt;&lt;/strong&gt;. The only reason for multitasking is because most tasks spend most of their execution time on waiting for an event or timeout happen. If we can run other pieces of codes when waiting for an event, performance must increase a lots. The benefit of multitasking is&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;(1) avoid long response time due to waiting for event, (2) better utilize resource, keep them all busy.&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;The following shows typical task code:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-types&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &#39;Courier New&#39;;&quot;&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;task&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-types&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &#39;Courier New&#39;;&quot;&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; *&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;data&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;init_task&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #5555dd; font-family: &#39;Courier New&#39;;&quot;&gt;while&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &#39;Courier New&#39;;&quot;&gt;TRUE&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;Wait&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #5555dd; font-family: &#39;Courier New&#39;;&quot;&gt;for&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;message&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;at&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;task&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;mailbox&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-comment&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #449944; font-family: &#39;Courier New&#39;;&quot;&gt;        // go to pending(blocked) queue if message is not ready&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #5555dd; font-family: &#39;Courier New&#39;;&quot;&gt;switch&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;message&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;type&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #5555dd; font-family: &#39;Courier New&#39;;&quot;&gt;case&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;MESSAGE_TYPE_X&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-comment&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #449944; font-family: &#39;Courier New&#39;;&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #5555dd; font-family: &#39;Courier New&#39;;&quot;&gt;break&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #5555dd; font-family: &#39;Courier New&#39;;&quot;&gt;case&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;MESSAGE_TYPE_Y&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-comment&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #449944; font-family: &#39;Courier New&#39;;&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #5555dd; font-family: &#39;Courier New&#39;;&quot;&gt;break&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;apple-style-span&quot;&gt;It is similar to code of polled waiting, but they are different things. After&lt;/span&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;initialization&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-style-span&quot;&gt;, it runs a&lt;/span&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;infinite loop&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;apple-style-span&quot;&gt;which is to wait for a specific event or message, and then processes the message. In a typical embedded system, tasks are viewed as&lt;/span&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;background&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-style-span&quot;&gt;procedures, and the ISR that provides the message are viewed as&lt;/span&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;foreground&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;apple-style-span&quot;&gt;procedures.&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;apple-style-span&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;apple-style-span&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;h2&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &#39;Century Gothic&#39;, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;How does it work&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;&lt;h2&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000; font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small; line-height: 20px;&quot;&gt;Semaphore&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;&lt;h2&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: small; font-weight: normal; line-height: 20px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;/span&gt;When the task tries to obtain message data, it&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;calls Wait()&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;on a semaphore. If message has not been ready, the task is blocked. When the corresponding ISR generates the message, the&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;ISR calls Signal()&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;on this semaphore, and wake up the task. The task can then process the data.&lt;/span&gt;&lt;/h2&gt;&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;b&gt;System call&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 15.6pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif;&quot;&gt;When the task tries to obtain message data, it call the system call Block() if the data has not been ready, so CPU will execute other tasks. When the corresponding ISR generates the message, the ISR first calls a system call to&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;change the status&lt;/span&gt;&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;of this task&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;from pending to ready&lt;/span&gt;&lt;/strong&gt;, and then calls a system call to&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;execute the CPU scheduler&lt;/span&gt;&lt;/strong&gt;. After that, the scheduler might (or might not, may depend on the priority) wake up the task to process the data.&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 11pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/599500738068244164/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/multi-tasking.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/599500738068244164'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/599500738068244164'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/multi-tasking.html' title='Multi Tasking or Multi Thread'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-2130888820573043314</id><published>2011-01-09T01:15:00.000-08:00</published><updated>2011-01-10T22:14:38.166-08:00</updated><title type='text'>OS concept - Synchronization</title><content type='html'>&lt;h2&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &#39;Century Gothic&#39;, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Synchronization is an important concept in Operating System. Producer/Consumer and Reader/Writer are two examples of synchronization problems. The following is the sample codes for them.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;&lt;h2&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &#39;Century Gothic&#39;, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Producer and Consumer&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15pt; font-weight: normal;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-types&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &#39;Courier New&#39;;&quot;&gt;int&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;buf&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;[&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;N&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;, &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;in&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; = &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-number&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: maroon; font-family: &#39;Courier New&#39;;&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;, &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;out&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; = &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-number&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: maroon; font-family: &#39;Courier New&#39;;&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;sem&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;filledslots&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; = &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-number&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: maroon; font-family: &#39;Courier New&#39;;&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;, &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;emptyslots&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; = &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;N&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;, &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;mutex&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; = &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-number&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: maroon; font-family: &#39;Courier New&#39;;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;Producer&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;wait&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;emptyslots&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;   &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #6aa84f;&quot;&gt;//synchronization start&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;wait&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;mutex&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;        &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #6aa84f;&quot;&gt;//critical section start&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;Produce&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;buf&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;[&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;in&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;])&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;in&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; = &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;in&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; + &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-number&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: maroon; font-family: &#39;Courier New&#39;;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; % &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;N&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;signal&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;mutex&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;      &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #6aa84f;&quot;&gt;//critical section end&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;signal&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;filledslots&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #6aa84f;&quot;&gt;//synchronization end&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;Consumer&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;wait&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;filledslots&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;  &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #6aa84f;&quot;&gt;//synchronization start&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;wait&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;mutex&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;        &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #6aa84f;&quot;&gt;//critical section start&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;Consume&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;buf&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;[&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;out&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;])&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;out&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; = &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;out&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; + &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-number&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: maroon; font-family: &#39;Courier New&#39;;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; % &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;N&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;signal&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;mutex&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;      &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #6aa84f;&quot;&gt;//critical section end&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;signal&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;emptyslots&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #6aa84f;&quot;&gt;//synchronization end&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;h2 id=&quot;toc1&quot; style=&quot;background: inherit;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &#39;Century Gothic&#39;, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Reader and Writer&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15pt; font-weight: normal;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-types&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &#39;Courier New&#39;;&quot;&gt;int&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;n&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; = &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-number&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: maroon; font-family: &#39;Courier New&#39;;&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;sem&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;mutex&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; = &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-number&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: maroon; font-family: &#39;Courier New&#39;;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;, &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;RW&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; = &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-number&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: maroon; font-family: &#39;Courier New&#39;;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;Reader&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;wait&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;mutex&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-comment&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #449944; font-family: &#39;Courier New&#39;;&quot;&gt;// lock reader&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;n&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;++;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #5555dd; font-family: &#39;Courier New&#39;;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;n&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; == &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-number&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: maroon; font-family: &#39;Courier New&#39;;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;wait&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;RW&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-comment&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #449944; font-family: &#39;Courier New&#39;;&quot;&gt;// lock first reader when there is a writer&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;signal&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;mutex&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;Read&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;wait&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;mutex&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #5555dd; font-family: &#39;Courier New&#39;;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;n&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; == &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-number&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: maroon; font-family: &#39;Courier New&#39;;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;signal&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;RW&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;n&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;--;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;signal&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;mutex&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;Writer&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;wait&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;RW&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-comment&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #449944; font-family: &#39;Courier New&#39;;&quot;&gt;// wait if at least one reader is reading&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;Write&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;signal&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;RW&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: #F7F7F7;&quot;&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/2130888820573043314/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/os-concept-synchronization.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/2130888820573043314'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/2130888820573043314'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/os-concept-synchronization.html' title='OS concept - Synchronization'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-2281452078981240274</id><published>2011-01-09T01:01:00.000-08:00</published><updated>2011-01-09T01:01:16.940-08:00</updated><title type='text'>Interrupt Vector Table</title><content type='html'>&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3c52be; font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;ul type=&quot;disc&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;When the system is&amp;nbsp;&lt;/span&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;booted up or reseted&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;, the interrupt is&amp;nbsp;&lt;/span&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;disabled&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&amp;nbsp;because      interrupt mechanism is not initialized.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Therefore, after booting up, one important task is to initialize      interrupt mechanism. For all system, we need to setup ISR&#39;s address.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Typically, ISR&#39;s addresses are stored in interrupt vector table, and      each device is assigned a specific number as the index to the interrupt      vector table for accessing their corresponding ISR (however, some      architectures are slightly different, such as ARM).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;The number assigned to each device are system dependent (ex. for      lpc2103… not processor dependent).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Interrupt vector table (its address, and so on) is processor      dependent.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/2281452078981240274/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/interrupt-vector-table.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/2281452078981240274'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/2281452078981240274'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/interrupt-vector-table.html' title='Interrupt Vector Table'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-7972698838187893506</id><published>2011-01-09T00:59:00.000-08:00</published><updated>2011-01-09T00:59:05.858-08:00</updated><title type='text'>ISR</title><content type='html'>&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Century Gothic&#39;, sans-serif;&quot;&gt;&lt;b&gt;You &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;must&lt;/span&gt; be asked questions about ISR in every firmware or embedded system interview!&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #8f2936; font-family: &#39;Century Gothic&#39;, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &#39;Century Gothic&#39;, sans-serif;&quot;&gt;&lt;b&gt;Interrupt Service Routine&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul type=&quot;disc&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;a href=&quot;http://book.opensourceproject.org.cn/embedded/oreillyembed/opensource/0596009836/id-i_0596009836_chp_8_sect_3.html&quot;&gt;&lt;span style=&quot;color: #3c52be; mso-bidi-font-size: 11.0pt;&quot;&gt;http://book.opensourceproject.org.cn/embedded/oreillyembed/opensource/0596009836/id-i_0596009836_chp_8_sect_3.html&lt;/span&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;A&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&amp;nbsp;&lt;b&gt;single ISR      (single interrupt)&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;may be&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&amp;nbsp;&lt;b&gt;triggered by multiple source&lt;/b&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;, then the ISR must include a&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&amp;nbsp;&lt;b&gt;condition test&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;to determine which      source causes this interrupt. Moreover, if multiple source trigger the      interrupt at the same time, the ISR must detect it, or it will result in&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&amp;nbsp;&lt;b&gt;interrupt missing&lt;/b&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &#39;Century Gothic&#39;, sans-serif;&quot;&gt;&lt;b&gt;Difference between ISR and normal function&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 15.6pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;1) ISR has no parameter&lt;br /&gt;
2) ISR has no return value&lt;br /&gt;
3) ISR is asynchronous to instruction flow&lt;br /&gt;
4) ISR is triggered by hardware event&lt;br /&gt;
5) ISR can&#39;t call blocking function or non-reentrant function, such as printf()&lt;br /&gt;
6) ISR should be as short as possible, shouldn&#39;t call function which require long time to execute, such as printf(), floating point function…&lt;br /&gt;
7) ISR can&#39;t be blocked, can&#39;t wait on semephor, but can signal&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &#39;Century Gothic&#39;, sans-serif;&quot;&gt;&lt;b&gt;Debugging ISR&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 15.6pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;a href=&quot;http://www.ganssle.com/articles/dbg-isr1.htm&quot;&gt;&lt;span style=&quot;color: #3c52be; mso-bidi-font-size: 11.0pt;&quot;&gt;http://www.ganssle.com/articles/dbg-isr1.htm&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;— ISR debugging 1&lt;br /&gt;
&lt;a href=&quot;http://www.ganssle.com/articles/dbg-isr2.htm&quot;&gt;&lt;span style=&quot;color: #3c52be; mso-bidi-font-size: 11.0pt;&quot;&gt;http://www.ganssle.com/articles/dbg-isr2.htm&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;— ISR debugging 2&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/7972698838187893506/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/isr.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/7972698838187893506'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/7972698838187893506'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/isr.html' title='ISR'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-8616363721396649923</id><published>2011-01-09T00:58:00.000-08:00</published><updated>2011-01-09T01:49:02.275-08:00</updated><title type='text'>Little Endian &amp; Big Endian</title><content type='html'>&lt;div style=&quot;font-style: normal; font-weight: normal; line-height: 0.24in; margin-left: 0.51in; text-indent: 0.31in;&quot;&gt;&lt;br /&gt;
Little Endian and Big Endian is an important concept in Embedded System and Firmware field. People who don&#39;t understand it will not be hired; people who clearly understands it and answer this kind of questions well can impress the interviewers.&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in; orphans: 2; widows: 2;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-style: normal; font-weight: normal; margin-bottom: 0in; orphans: 2; widows: 2;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;Different machines (CPU + OS) might use different Endianness. For example, Linux and Windows on x86 is Little Endian, but Linux on MIPS is Big Endian.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in; orphans: 2; widows: 2;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-style: normal; font-weight: normal; margin-bottom: 0in; orphans: 2; widows: 2;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;In the following article, we use the integer 0x12345678 to illustrate the definitions of Little/Big Endian.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0in; orphans: 2; widows: 2;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-style: normal; font-weight: normal; margin-bottom: 0in; orphans: 2; widows: 2;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Little Endian&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-style: normal; font-weight: normal; line-height: 0.24in; margin-left: 0.51in; orphans: 2; text-indent: 0.31in; widows: 2;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&quot;Little Endian&quot; means that the Low Significant Byte of a data is stored in memory at the lowest address, and the High Significant Byte at the highest address.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;2&quot; cellspacing=&quot;0&quot; style=&quot;width: 141px;&quot;&gt;&lt;col width=&quot;87&quot;&gt;&lt;/col&gt;  &lt;col width=&quot;46&quot;&gt;&lt;/col&gt;  &lt;tbody&gt;
&lt;tr&gt;   &lt;td width=&quot;87&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;mem addr&lt;/div&gt;&lt;/td&gt;   &lt;td width=&quot;46&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;data&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width=&quot;87&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;0x4000&lt;/div&gt;&lt;/td&gt;   &lt;td width=&quot;46&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;0x78&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width=&quot;87&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;0x4001&lt;/div&gt;&lt;/td&gt;   &lt;td width=&quot;46&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;0x56&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width=&quot;87&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;0x4002&lt;/div&gt;&lt;/td&gt;   &lt;td width=&quot;46&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;0x34&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width=&quot;87&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;0x4003&lt;/div&gt;&lt;/td&gt;   &lt;td width=&quot;46&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;0x12&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-style: normal; font-weight: normal; line-height: 0.19in; orphans: 2; widows: 2;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Big Endian&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-style: normal; font-weight: normal; line-height: 0.24in; margin-left: 0.51in; orphans: 2; text-indent: 0.31in; widows: 2;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&quot;Big Endian&quot; means that the High Significant Byte of a data is stored in memory at the lowest address, and the Low Significant Byte at the highest address.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;2&quot; cellspacing=&quot;0&quot; style=&quot;width: 141px;&quot;&gt;&lt;col width=&quot;87&quot;&gt;&lt;/col&gt;  &lt;col width=&quot;46&quot;&gt;&lt;/col&gt;  &lt;tbody&gt;
&lt;tr&gt;   &lt;td width=&quot;87&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;mem addr&lt;/div&gt;&lt;/td&gt;   &lt;td width=&quot;46&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;data&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width=&quot;87&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;0x4000&lt;/div&gt;&lt;/td&gt;   &lt;td width=&quot;46&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;0x12&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width=&quot;87&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;0x4001&lt;/div&gt;&lt;/td&gt;   &lt;td width=&quot;46&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;0x34&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width=&quot;87&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;0x4002&lt;/div&gt;&lt;/td&gt;   &lt;td width=&quot;46&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;0x56&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;   &lt;td width=&quot;87&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;0x4003&lt;/div&gt;&lt;/td&gt;   &lt;td width=&quot;46&quot;&gt;&lt;div align=&quot;LEFT&quot; style=&quot;border: none; padding: 0in;&quot;&gt;0x78&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-style: normal; font-weight: normal; line-height: 0.24in; margin-left: 0.51in; orphans: 2; text-indent: 0.31in; widows: 2;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;The advantage of Big Endian is that you can always determine whether a number is positive of negative by looking at the byte at offset zero, you don&#39;t need to know how long the number is, nor to skip over any bytes to find the byte containing the sign information. Also, when you print a number, you can print it from lowest bytes to highest bytes, and that is more easy and efficient.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;line-height: 0.19in; orphans: 2; widows: 2;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-style: normal; font-weight: normal; line-height: 0.19in; margin-bottom: 0in; orphans: 2; widows: 2;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Write a program to check the Endianness (Little or Small) on your machine&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre style=&quot;font-style: normal; font-weight: normal; line-height: 0.19in; orphans: 2; widows: 2;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times new roman&#39;, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;union {   &lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;// please make sure you understand &quot;union&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #990000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times new roman&#39;, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;unsigned int i;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #990000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times new roman&#39;, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;unsigned char c;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #990000;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times new roman&#39;, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;} u;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times new roman&#39;, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;int main()&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times new roman&#39;, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #990000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times new roman&#39;, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;u.i = &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #990000;&quot;&gt;&lt;span style=&quot;color: #5555dd;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times new roman&#39;, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;color: #5555dd;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;(u.c == &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #990000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times new roman&#39;, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;printf(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000099;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&quot;little edian\n&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #990000;&quot;&gt;&lt;span style=&quot;color: #5555dd;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times new roman&#39;, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;color: #5555dd;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;else&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #990000;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times new roman&#39;, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;printf(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000099;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&quot;big endian\n&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times new roman&#39;, serif;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-style: normal; font-weight: normal; line-height: 0.19in; orphans: 2; widows: 2;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times new roman&#39;, serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/8616363721396649923/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/little-endian-big-endian.html#comment-form' title='1 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/8616363721396649923'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/8616363721396649923'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/little-endian-big-endian.html' title='Little Endian &amp; Big Endian'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-1000561384462567722</id><published>2011-01-09T00:55:00.000-08:00</published><updated>2011-01-09T00:55:18.501-08:00</updated><title type='text'>Interrupt</title><content type='html'>&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &#39;Century Gothic&#39;, sans-serif;&quot;&gt;&lt;b&gt;What is Interrupt&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 25pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul type=&quot;disc&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l1 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Hardware Interrupt — A hardware interrupt is a signal which can tell      the CPU that something happen in hardware device, and should be      immediately responded. A interrupt causes the processor to save its state      of execution and begin execution of an interrupt service routine.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;ul type=&quot;disc&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l5 level1 lfo2; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Software Interrupt — Software interrupt is an instruction which cause      a context switch to an interrupt handler similar to a hardware interrupt.      Usually it is an interrupt generated within a processor by executing an      instruction. Software interrupts are often used to implement&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;i&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;system calls&lt;/span&gt;&lt;/i&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &#39;Century Gothic&#39;, sans-serif;&quot;&gt;&lt;b&gt;Interrupt Latency&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 25pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul type=&quot;disc&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l0 level1 lfo3; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;when an interrupt fires, the microprocessor executes an interrupt      service routine (ISR). The amount of time that elapses between a device      interrupt request and the first instruction of the corresponding ISR is      known as interrupt latency.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &#39;Century Gothic&#39;, sans-serif;&quot;&gt;&lt;b&gt;Reduce Interrupt Latency&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 25pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul type=&quot;disc&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l2 level1 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;We should make all&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&amp;nbsp;&lt;b&gt;ISR as      short as possible&lt;/b&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;, because other ISR that      has lower priority will be blocked by it.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l2 level1 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;If we disable interrupt in an ISR or process for protecting critical sections,      we should&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&amp;nbsp;&lt;b&gt;enable it as      early as possible&lt;/b&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;. Once we finish the task      which is non-reentrant in an ISR, its time to enable interrupt.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l2 level1 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;We can also reenable all ISR before the current ISR finish its      non-reentrant task. Therefore, the current ISR won&#39;t degrade the latency      of other ISR. However, we need to prevent interrupt overrun by setting up      the corresponding mask bit or using a static to notify the ISR is      currently triggered. Notice that preventing interrupt overrun means that      some interrupts will miss.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l2 level1 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Use&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&amp;nbsp;&lt;b&gt;inline assembly      language&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;to replace some lines of      ISR code in C, and reduce some overhead introduced by C.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 15.6pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Interrupt&quot;&gt;&lt;span style=&quot;color: #3c52be; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;&quot;&gt;http://en.wikipedia.org/wiki/Interrupt&lt;/span&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &#39;Century Gothic&#39;, sans-serif;&quot;&gt;&lt;b&gt;Interrupt vs Exception&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 25pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 15.6pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;The definitions are different everywhere. Here are some reasonable conclusions I made:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul type=&quot;disc&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l4 level1 lfo5; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Interrupt includes hardware interrupt and software interrupt;      Exception includes trap, fault, and abort.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l4 level1 lfo5; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Hardware interrupt is asynchronous, and others (exceptions and      software interrupt) are synchronous to instructions.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l4 level1 lfo5; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Software interrupt are used to implement system call. In intel      processor, we use INT instruction. In MIPS we use syscall.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 15.6pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Ex. Fork() System Call — Intel x86 &amp;amp; Linux&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;__asm__ (&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #000099; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&quot;movl $2, %%eax&lt;/span&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: navy; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;\&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #000099; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;n&lt;/span&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: navy; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;\&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #000099; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;t&quot;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #449944; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;// move 2 into eax, 2 is the number for fork() system call&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #000099; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&quot;int $0x80&lt;/span&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: navy; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;\&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #000099; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;n&lt;/span&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: navy; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;\&lt;/span&gt;&lt;/b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #000099; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;t&quot;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #449944; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;// int 0x80 execute a software interrupt that deal with system call &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;:&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #000099; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&quot;=a&quot;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt; (chPid)&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #449944; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;// return value of Fork()&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;);&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 15.6pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Ex. Open() System Call — MIPS&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;Void open (&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;char&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt; *file_name) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #5555dd; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;asm&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;load OpenSystemCallNum, r8&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;move filename, r9&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;syscall&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #449944; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;// when syscall is executed, CPU load PC with address stored in interrupt vector table&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;}&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #449944; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;// using OpenSystemCallNum as the table index, and jump to the associated ISR&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: #F7F7F7; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;}&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Courier New&amp;quot;; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul type=&quot;disc&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;color: #333333; mso-list: l3 level1 lfo6; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan; tab-stops: list 36.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;Software interrupt and trap are sometime considered as the same      thing. That&#39;s why some definitions say system call is trap.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &#39;Century Gothic&#39;, sans-serif;&quot;&gt;&lt;b&gt;IRQ &amp;amp; FIQ (ARM based CPU)&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 25pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 15.6pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&quot;IRQ is serviced at a normal priority level and FIQ is serviced at high priority level.&quot;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 15.6pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;FIQ is the fast interrupt i.e. the latency time taken is less because in the FIQ mode (in case of ARM architecture where these modes are encountered) the mode&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&amp;nbsp;&lt;b&gt;has an additional set of 7 general purpose registers&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;which means in case of the banked registers there is no need to store these registers into stack when the interrupt occurs.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 15.6pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;That means&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&amp;nbsp;&lt;b&gt;only r0 to r7 need to be stored while moving from User mode to FIQ mode whereas while moving from User mode to IRQ mode r0 to r12 needs to be stored.&lt;/b&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #8f2936; font-family: &#39;Century Gothic&#39;, sans-serif;&quot;&gt;&lt;b&gt;Reference&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 15.6pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-pagination: widow-orphan;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #333333; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: 新細明體; mso-font-kerning: 0pt;&quot;&gt;&lt;a href=&quot;http://www.cs.fsu.edu/~xyuan/cop4610/lecture_2_concurrency.ppt&quot;&gt;&lt;span style=&quot;color: #3c52be; mso-bidi-font-size: 11.0pt; text-decoration: none; text-underline: none;&quot;&gt;http://www.cs.fsu.edu/~xyuan/cop4610/lecture_2_concurrency.ppt&lt;/span&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/1000561384462567722/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/interrupt.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/1000561384462567722'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/1000561384462567722'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/interrupt.html' title='Interrupt'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-5802542679159173911</id><published>2011-01-09T00:12:00.000-08:00</published><updated>2011-01-09T00:13:46.336-08:00</updated><title type='text'>String (2)</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 13px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-size: 13px; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Return the 1st non-repeated character: Ex.&quot;aaaaaaak47&quot; return &#39;k&#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-size: 13px; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-types&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;find_first_nonrepeat&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-types&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-types&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c1 = str;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;    char &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;pre_c = *c1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != &#39;\&lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&#39; &amp;amp;&amp;amp; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; == &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;pre_c&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;    {      &amp;nbsp;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;pre_c&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;; &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// If the same as previous char&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;        c1++;  &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;     &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;//&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;add c1 by 1 &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;and go to next char&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;    }&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; == &#39;\&lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;) &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// Be careful the special case!&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;    &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// =&amp;gt; all chars are the same&lt;/span&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;; &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// This is to return a char, not pointer&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;                     &lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Convert an Integer to a String&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-size: 13px; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-types&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;* &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;num2str&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-types&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;hl-types&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-types&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;/=&lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; % &lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; + &#39;&lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&#39;;&lt;br /&gt;    *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &#39;\&lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&#39;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; - &lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;        &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// After that we need to reverse the string,&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;                    &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// since string c starts from lower digit.&lt;/span&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &amp;lt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c2&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// It is a different way to reverse a string&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; ^= *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;    &lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; ^= *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;++ ^= *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;--;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Compare 2 strings. If equal return 1, else return 0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-size: 13px; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;hl-types&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Same&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-types&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;s1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;hl-types&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;s2&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-types&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;s1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;s2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != &#39;\&lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&#39; &amp;amp;&amp;amp; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != &#39;\&lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&#39; &amp;amp;&amp;amp; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; == *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c2&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;++;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;++;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; == &#39;\&lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&#39; &amp;amp;&amp;amp; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;c2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; == &#39;\&lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;  &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// If while loop goes to the end =&amp;gt; equal&lt;/span&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/5802542679159173911/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/string-2.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/5802542679159173911'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/5802542679159173911'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/string-2.html' title='String (2)'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-6829374397107754886</id><published>2011-01-09T00:00:00.000-08:00</published><updated>2011-01-09T00:13:46.357-08:00</updated><title type='text'>Linked List (4)</title><content type='html'>&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Find the middle item in a Linked List&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-size: 13px; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-types&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;find_middle&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &amp;amp;&amp;amp; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// p1 goes 2 steps; p2 goes 1 step&lt;/span&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// when p1 to the end, p2 points to middle&lt;/span&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Determine if there is a loop in a Linked List&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-size: 13px; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-types&quot;&gt;bool&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;find_loop&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &amp;amp;&amp;amp; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// p1 goes 2 steps; p2 goes 1 step&lt;/span&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; == &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;) &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// If there is loop, we must get p1 == p2 &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;            &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;  &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// sooner or later&lt;/span&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;     &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// If goes out of the while, no loop.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Find merge point of two Linked Lists (if there is one)&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-size: 13px; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;* &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Find_merge_point&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;h2&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-types&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Length1&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; - &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Length1&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;h2&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &amp;gt;= &lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{  &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// make p1 to be longer one &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;h2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *= -&lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;h2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// n is the length diff. between p1 and p2&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// make p1 and p2 &quot;aligned&quot; &lt;/span&gt;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &amp;amp;&amp;amp; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &amp;amp;&amp;amp; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// start to check merge point&lt;/span&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; == &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; || &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; == &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot; style=&quot;color: #000099;&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;hl-string&quot; style=&quot;color: #000099;&quot;&gt;can&#39;t find merge point!&lt;/span&gt;&lt;span class=&quot;hl-special&quot; style=&quot;color: navy; font-weight: bold;&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;hl-string&quot; style=&quot;color: #000099;&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot; style=&quot;color: #000099;&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/6829374397107754886/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/linked-list-4.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/6829374397107754886'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/6829374397107754886'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/linked-list-4.html' title='Linked List (4)'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-8245535744473040221</id><published>2011-01-08T23:56:00.000-08:00</published><updated>2011-01-09T00:13:46.379-08:00</updated><title type='text'>Linked List (3)</title><content type='html'>&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Sum up values of all items in a Linked List (items are integers)&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-size: 13px; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-types&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Sum&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; == &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; + &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Sum&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Print all items in a Linked List&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-size: 13px; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-size: 13px; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-types&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Print1&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; == &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;) &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// Special Case! head is null!&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot; style=&quot;color: #000099;&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;hl-string&quot; style=&quot;color: #000099;&quot;&gt;%d &lt;/span&gt;&lt;span class=&quot;hl-quotes&quot; style=&quot;color: #000099;&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Print1&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Reversely print all items&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-size: 13px; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-types&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Print&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; == &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Print&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;        &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// Recursively call itself, &lt;/span&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot; style=&quot;color: #000099;&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;hl-string&quot; style=&quot;color: #000099;&quot;&gt;%d &lt;/span&gt;&lt;span class=&quot;hl-quotes&quot; style=&quot;color: #000099;&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// so last one is printed first.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Find the last Mth item: Ex.find the last 2th in 1-&amp;gt;4-&amp;gt;5-&amp;gt;2-&amp;gt;9-&amp;gt;0-&amp;gt;3-&amp;gt;Null =&amp;gt; 0&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-size: 13px; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;* &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Find_Mth_Last&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; **&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;hl-types&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &amp;gt;= &lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &amp;amp;&amp;amp; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-comment&quot; style=&quot;color: #449944;&quot;&gt;// p1 goes to Mth first&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;             &lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; -= &lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != -&lt;/span&gt;&lt;span class=&quot;hl-number&quot; style=&quot;color: maroon;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;hl-comment&quot; style=&quot;color: #449944;&quot;&gt;// if we can find out, M == -1, not M == 0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot; style=&quot;color: #000099;&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;hl-string&quot; style=&quot;color: #000099;&quot;&gt;can&#39;t find Mth, because its shorter than M!&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot; style=&quot;color: #000099;&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;         &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// p2 points to 1st&lt;/span&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// when p1 to the end, p2 points to Mth&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;    &lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/8245535744473040221/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/linked-list-3.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/8245535744473040221'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/8245535744473040221'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/linked-list-3.html' title='Linked List (3)'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-1591063405763676724</id><published>2011-01-08T23:53:00.000-08:00</published><updated>2011-01-09T00:13:46.411-08:00</updated><title type='text'>Linked List (2)</title><content type='html'>&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Insert an item into a Circular Linked List&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-size: 13px; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-types&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;insert_circular&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; **&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;hl-types&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;malloc&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; == &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;br /&gt;        *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;   &lt;/span&gt;&lt;span class=&quot;hl-comment&quot; style=&quot;color: #449944;&quot;&gt;// for circular linked list &lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-comment&quot; style=&quot;color: #449944;&quot;&gt;// find the node before head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;            &lt;/span&gt;&lt;span class=&quot;hl-comment&quot; style=&quot;color: #449944;&quot;&gt;// insert head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Insert an item into a Double Linked List&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-size: 13px; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-types&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;insert_double&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;** &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;hl-types&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt; &lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;malloc&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; -&amp;gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;         &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; == &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;prev&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &amp;amp;&amp;amp; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &amp;gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; == *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{    &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// Special Case!&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;prev&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;prev&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;            &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;prev&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p2&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Delete an item in a Linked List&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-size: 13px; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;* &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Remove&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;hl-types&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;temp&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &amp;amp;&amp;amp; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; == &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;               &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// Special Case! &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;can&#39;t find&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot; style=&quot;color: #000099;&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;hl-string&quot; style=&quot;color: #000099;&quot;&gt;can&#39;t find item&lt;/span&gt;&lt;span class=&quot;hl-special&quot; style=&quot;color: navy; font-weight: bold;&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;hl-string&quot; style=&quot;color: #000099;&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot; style=&quot;color: #000099;&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; == &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;       &lt;/span&gt;&lt;span class=&quot;hl-comment&quot; style=&quot;color: #449944;&quot;&gt;//&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;Special Case! &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;find out at head&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;free&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;                       &lt;/span&gt;&lt;span class=&quot;hl-comment&quot; style=&quot;color: #449944;&quot;&gt;// otherwise&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;free&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Reverse a Linked List: Ex. 1-&amp;gt;7-&amp;gt;5-&amp;gt;3-&amp;gt;Null =&amp;gt; 3-&amp;gt;5-&amp;gt;7-&amp;gt;1-&amp;gt;Null&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;* &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Reverse&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;* &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;temp&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// reverse linked list&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;temp&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// you could draw a linked list on paper,&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;  &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// to understand why it reverses the list.&lt;/span&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;temp&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;       &lt;/span&gt;&lt;span class=&quot;hl-comment&quot; style=&quot;color: #449944;&quot;&gt;// if head == NULL, p0 is also NULL&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/1591063405763676724/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/linked-list-2.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/1591063405763676724'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/1591063405763676724'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/linked-list-2.html' title='Linked List (2)'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-4745450087858932154</id><published>2011-01-08T23:50:00.000-08:00</published><updated>2011-01-09T00:13:46.434-08:00</updated><title type='text'>Linked List (1)</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 13px; line-height: 20px;&quot;&gt;Linked List is a very important data structure in Firmware field. Almost all Firmware interviewers will ask at least 1 &amp;nbsp;linked list question! Here are many linked list questions and their example solution. If you cannot understand the example solution in the first glance, you could draw the linked list on a paper to help you understand each line of code.&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 13px; line-height: 20px;&quot;&gt;Before you go for a firmware interview, please make sure you can solve each question within 15 minutes. After practicing all of these questions (or most of them), you should be able to handle all linked list questions in your interview.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px; line-height: 20px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;Create Linked List&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 13px; line-height: normal;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 13px; line-height: normal;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 13px; line-height: normal;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 13px; line-height: normal;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;* &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Create&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-types&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;malloc&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;; &lt;/span&gt;&lt;span class=&quot;hl-comment&quot; style=&quot;color: #449944;&quot;&gt;// create a dummy head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;scanf&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot; style=&quot;color: #000099;&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;hl-string&quot; style=&quot;color: #000099;&quot;&gt;%d&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot; style=&quot;color: #000099;&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, &amp;amp;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;malloc&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;             &lt;/span&gt;&lt;span class=&quot;hl-comment&quot; style=&quot;color: #449944;&quot;&gt;// kill the dummy head now&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;free&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000; font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px; white-space: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Insert an item to the head of a Linked List&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000; font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small; line-height: 20px; white-space: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 13px; line-height: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-types&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; **&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;hl-types&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;malloc&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; white-space: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000; font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px; white-space: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;Insert an item into a sorted Linked List: Ex.insert 4 into 1-&amp;gt;3-&amp;gt;7-&amp;gt;8 =&amp;gt; 1-&amp;gt;3-&amp;gt;4-&amp;gt;7-&amp;gt;8&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; margin: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000; font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small; line-height: 20px; white-space: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 13px; line-height: normal;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;* &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Insert_Sorted&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;hl-types&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, *&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;, *&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;malloc&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; != &lt;/span&gt;&lt;span class=&quot;hl-prepro&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &amp;amp;&amp;amp; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &amp;lt;= &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; == &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;   &lt;/span&gt;&lt;span class=&quot;hl-comment&quot; style=&quot;color: #449944;&quot;&gt;// be careful Special Case! &lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;     &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #449944;&quot;&gt;// may stop at the head!&lt;/span&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;              &lt;/span&gt;&lt;span class=&quot;hl-comment&quot; style=&quot;color: #449944;&quot;&gt;// otherwise&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p0&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;p1&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;    &lt;br /&gt; &lt;br /&gt;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot; style=&quot;color: #5555dd;&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot; style=&quot;color: black;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl-code&quot; style=&quot;color: black;&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;hl-brackets&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/4745450087858932154/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/linked-list-1.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/4745450087858932154'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/4745450087858932154'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/linked-list-1.html' title='Linked List (1)'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5878854192616837919.post-1148730225576431236</id><published>2011-01-08T19:10:00.000-08:00</published><updated>2011-01-08T23:35:10.963-08:00</updated><title type='text'>Dynamic Memory Allocation</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: arial, sans-serif; font-style: normal; line-height: 15px;&quot;&gt;&lt;em style=&quot;color: #cc0033; font-style: normal;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;b&gt;In a software or firmware interview, you may be asked about dynamic memory allocation in different way.&lt;/b&gt;&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: arial, sans-serif; font-style: normal; line-height: 15px;&quot;&gt;&lt;em style=&quot;color: #cc0033; font-style: normal; font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/em&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000; font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, sans-serif; font-style: normal; line-height: 15px;&quot;&gt;&lt;em style=&quot;font-style: normal;&quot;&gt;&lt;b&gt;What is dynamically memory allocation?&lt;/b&gt;&lt;/em&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 15px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif; font-weight: normal; line-height: 19px;&quot;&gt;dynamic memory allocation&amp;nbsp;(heap-based memory allocation) is the allocation &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif; font-weight: normal; line-height: 19px;&quot;&gt;of&amp;nbsp;memory&amp;nbsp;storage du&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif; font-weight: normal; line-height: 19px;&quot;&gt;ring the runtime&amp;nbsp;of that program.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif; line-height: 19px;&quot;&gt;Dynamically allocated memory exists until it is released either explicitly by the programmer.&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif; line-height: 19px;&quot;&gt;It is said that this object has a&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot;&gt;dynamic lifetime.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: arial, sans-serif; font-style: normal; line-height: 15px;&quot;&gt;&lt;em style=&quot;color: #cc0033; font-style: normal; font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/em&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000; font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, sans-serif; font-style: normal; line-height: 15px;&quot;&gt;&lt;em style=&quot;font-style: normal;&quot;&gt;&lt;b&gt;How to dynamically allocate memory in C?&lt;/b&gt;&lt;/em&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px;&quot;&gt;&lt;i&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, sans-serif; font-style: normal; line-height: 15px;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;em style=&quot;color: #cc0033; font-style: normal; font-weight: normal;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;malloc&lt;/span&gt;&lt;/em&gt;()&lt;/span&gt; provides&amp;nbsp;&lt;/span&gt;&lt;em style=&quot;color: #cc0033; font-style: normal; font-weight: normal;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;dynamic&lt;/span&gt;&lt;/em&gt;&amp;nbsp;memory&lt;/span&gt; allocation&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, sans-serif; font-style: normal; line-height: 15px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, sans-serif; line-height: 15px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif; line-height: 20px;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;em style=&quot;background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; font-style: normal; margin: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/em&gt;&lt;span style=&quot;background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; margin: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;i&gt;void *&amp;nbsp; malloc (&amp;nbsp; size_t&amp;nbsp; size )&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, sans-serif; font-style: normal; line-height: 15px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif; line-height: 20px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif; line-height: 20px;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;The type of returned pointer is *void since malloc doesn&#39;t know how you are going to use the allocated memory, so you need to cast it before using&lt;/span&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif; line-height: 20px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000; font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif; line-height: 20px;&quot;&gt;&lt;b&gt;Memory Leak&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;When you don&#39;t need the allocated memory anymore, you must free it by calling free(). If you forgot to do it, the allocated memory will be always reserved and the system cannot use it, it is so called &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;memory leak&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; line-height: 20px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Arial; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, sans-serif; font-style: normal; line-height: 15px;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;free()&lt;/span&gt; releases the allocated memory.&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, sans-serif; font-style: normal; line-height: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: black; font-family: Arial; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, sans-serif; line-height: 15px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif; line-height: 20px;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;void&amp;nbsp; free (&amp;nbsp; void *p )&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000; font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px;&quot;&gt;&lt;b&gt;Example&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;int *pA ;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pA = ( int *) malloc (sizeof (int) * 10 ) ; &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #45818e;&quot;&gt;&amp;nbsp;//&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif; line-height: 20px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #45818e;&quot;&gt;allocate 10 int ( 40 bytes )&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #45818e;&quot;&gt;//use the allocated memory here&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 20px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;free(pA); &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #45818e;&quot;&gt;//release the memory&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-family: arial, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000; font-family: arial, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 15px;&quot;&gt;&lt;b&gt;Where is the dynamically allocated memory located?&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 15px;&quot;&gt;The memory allocated by using malloc will be located in &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;heap section&lt;/span&gt;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000; font-family: arial;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: &#39;Helvetica Neue&#39;, &#39;Liberation Sans&#39;, Arial, Verdana, Helvetica, FreeSans, sans-serif; font-weight: normal; line-height: 20px;&quot;&gt;&lt;em style=&quot;background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; margin: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;br /&gt;&lt;/em&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://firmwareinterviewcracker.blogspot.com/feeds/1148730225576431236/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/dynamic-memory-allocation.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/1148730225576431236'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5878854192616837919/posts/default/1148730225576431236'/><link rel='alternate' type='text/html' href='http://firmwareinterviewcracker.blogspot.com/2011/01/dynamic-memory-allocation.html' title='Dynamic Memory Allocation'/><author><name>Embedded Firmware Interview Cracker</name><uri>http://www.blogger.com/profile/09607716724658457351</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQpNBCyQXGbt5oL28p1uwKo6EnWIojbFl3hx7dhJUtAHTNo8iWeAId6VpJFVSgqSGUfo4j9tjCY0yN6MKkEEEvjAJzKuNtICNS1LRU_rTTJ_OUnzOb0tHcAvJrSgXnTg/s220/image6.jpg'/></author><thr:total>0</thr:total></entry></feed>