{"id":644,"date":"2025-07-21T12:05:53","date_gmt":"2025-07-21T12:05:53","guid":{"rendered":"https:\/\/tipcontrol.com\/?page_id=644"},"modified":"2025-07-21T12:05:53","modified_gmt":"2025-07-21T12:05:53","slug":"critical-keyword","status":"publish","type":"page","link":"https:\/\/tipcontrol.com\/?page_id=644","title":{"rendered":"critical keyword"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\"><code>critical {...}<\/code>&nbsp;Keyword Documentation<\/h3>\n\n\n\n<p>The <code>critical<\/code> keyword is used to denote a block of code that must be executed without interruption. This ensures that critical sections of code are executed as fast and effectively as possible, also the accuracy of delays is increased as no switching between different tasks is possible. Warning it is not recommended to stay in a critical section for a longer time, as processing of drivers and execution of messages is not possible while the critical section is executed.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Structure of the&nbsp;<code>critical<\/code>&nbsp;Block<\/h4>\n\n\n\n<p>The <code>critical<\/code> block is used to enclose code that must complete without being preempted:<\/p>\n\n\n\n<p><strong>Components<\/strong>:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong><code>critical<\/code>\u00a0Keyword<\/strong>: Used to declare the start of a critical section.<\/li>\n\n\n\n<li><strong>Code Block<\/strong>: The code within the curly braces\u00a0<code>{}<\/code>\u00a0is executed without interruptions.<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">Simple Example<\/h4>\n\n\n\n<p>Here\u2019s a hypothetical example demonstrating the use of the <code>critical<\/code> block in a program:<\/p>\n\n\n\n<p>\/\/ A speed test critical { \/\/ Start of critical section start = lib.time.getTime(0); \/\/get current milliseconds running<\/p>\n\n\n\n<p>for(i=0,i&lt;10000,i+=1) drv.digitalIO.toggle();<\/p>\n\n\n\n<p>millis = lb.time.getTime(0) -start; \/\/ End of critical section };<\/p>\n\n\n\n<p>lib.log(\u201cExecution took \u201c+millis+ \u201c ms\u201d);<\/p>\n\n\n\n<p><strong>Explanation<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Speed Test<\/strong>: Assumes a test for the highest possible toggling speed of a pin using Tipcontrol.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Practical Use<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Concurrency Control<\/strong>: Even tough variables in TipControl are thread safe, if you need concurrent operations on the same variable, which is also accessed by paralel code you might need critical.<\/li>\n\n\n\n<li><strong>Real-time Systems<\/strong>: Ensure time-critical operations are completed without preemption in real-time systems.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Considerations<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Blocking Nature<\/strong>: Code inside a\u00a0<code>critical<\/code>\u00a0block will block other threads , so make the code as brief as possible to minimize impact on system responsiveness.<\/li>\n\n\n\n<li><strong>Deadlock<\/strong>: Be cautious when using critical sections , endless loops within critical section can completly block the execution of the TipControl system.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>critical {&#8230;}&nbsp;Keyword Documentation The critical keyword is used to denote a block of code that must be executed without interruption. This ensures that critical sections of code are executed as fast and effectively as possible, also the accuracy of delays is increased as no switching between different tasks is possible. Warning it is not recommended [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-644","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages\/644","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=644"}],"version-history":[{"count":1,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages\/644\/revisions"}],"predecessor-version":[{"id":645,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages\/644\/revisions\/645"}],"wp:attachment":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}