{"id":3344,"date":"2025-06-05T04:19:58","date_gmt":"2025-06-05T04:19:58","guid":{"rendered":"https:\/\/diznr.com\/?p=3344"},"modified":"2025-06-05T04:19:58","modified_gmt":"2025-06-05T04:19:58","slug":"process-synchronization-two-process-solution-algo-3-l-algorithm-deckers","status":"publish","type":"post","link":"https:\/\/www.reilsolar.com\/pdf\/process-synchronization-two-process-solution-algo-3-l-algorithm-deckers\/","title":{"rendered":"Process Synchronization Two Process Solution) (Algo-3) l Decker&#8217;s Algorithm."},"content":{"rendered":"<p>Process Synchronization Two Process Solution) (Algo-3) l Decker&#8217;s Algorithm.<\/p>\n<p>[fvplayer id=&#8221;362&#8243;]<\/p>\n<h3 data-start=\"0\" data-end=\"86\"><strong data-start=\"4\" data-end=\"84\">Dekker\u2019s Algorithm \u2013 Process Synchronization (Two-Process Solution) (Algo-3)<\/strong><\/h3>\n<p data-start=\"88\" data-end=\"317\"><strong data-start=\"88\" data-end=\"110\">Dekker\u2019s Algorithm<\/strong> is one of the earliest known solutions to the <strong data-start=\"157\" data-end=\"185\">critical section problem<\/strong> for two processes running in a shared memory environment. It ensures <strong data-start=\"255\" data-end=\"275\">mutual exclusion<\/strong>, <strong data-start=\"277\" data-end=\"289\">progress<\/strong>, and <strong data-start=\"295\" data-end=\"314\">bounded waiting<\/strong>.<\/p>\n<h3 data-start=\"324\" data-end=\"365\"><strong data-start=\"327\" data-end=\"363\">Problem: Process Synchronization<\/strong><\/h3>\n<p data-start=\"366\" data-end=\"492\">When multiple processes access shared resources, they need to be synchronized to avoid race conditions and ensure consistency.<\/p>\n<h3 data-start=\"499\" data-end=\"536\"><strong data-start=\"502\" data-end=\"534\">Solution: Dekker\u2019s Algorithm<\/strong><\/h3>\n<p data-start=\"537\" data-end=\"586\">Dekker\u2019s Algorithm uses the following mechanisms:<\/p>\n<ol data-start=\"587\" data-end=\"732\">\n<li data-start=\"587\" data-end=\"671\"><strong data-start=\"590\" data-end=\"609\">Flags (want[2])<\/strong> \u2013 Indicates if a process wants to enter the critical section.<\/li>\n<li data-start=\"672\" data-end=\"732\"><strong data-start=\"675\" data-end=\"692\">Turn Variable<\/strong> \u2013 Specifies which process has priority.<\/li>\n<\/ol>\n<h3 data-start=\"734\" data-end=\"758\"><strong data-start=\"738\" data-end=\"758\">Algorithm Steps:<\/strong><\/h3>\n<h4 data-start=\"759\" data-end=\"786\"><strong data-start=\"764\" data-end=\"786\">1. Initialization:<\/strong><\/h4>\n<ul data-start=\"790\" data-end=\"922\">\n<li data-start=\"790\" data-end=\"869\"><code data-start=\"792\" data-end=\"819\">want[0] = want[1] = false<\/code> (Initially, both processes do not want to enter.)<\/li>\n<li data-start=\"873\" data-end=\"922\"><code data-start=\"875\" data-end=\"885\">turn = 0<\/code> (Process 0 gets priority initially.)<\/li>\n<\/ul>\n<h4 data-start=\"924\" data-end=\"950\"><strong data-start=\"929\" data-end=\"950\">2. Entry Section:<\/strong><\/h4>\n<ul data-start=\"954\" data-end=\"1189\">\n<li data-start=\"954\" data-end=\"1014\">A process sets its <code data-start=\"975\" data-end=\"991\">want[i] = true<\/code> (indicating interest).<\/li>\n<li data-start=\"1018\" data-end=\"1189\">If the other process (<code data-start=\"1042\" data-end=\"1045\">j<\/code>) also wants to enter:\n<ul data-start=\"1073\" data-end=\"1189\">\n<li data-start=\"1073\" data-end=\"1115\">The process waits if it is not its turn.<\/li>\n<li data-start=\"1121\" data-end=\"1189\">If it&#8217;s not its turn, it sets <code data-start=\"1153\" data-end=\"1170\">want[i] = false<\/code> and retries later.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4 data-start=\"1191\" data-end=\"1225\"><strong data-start=\"1196\" data-end=\"1225\">3. Critical Section (CS):<\/strong><\/h4>\n<ul data-start=\"1229\" data-end=\"1273\">\n<li data-start=\"1229\" data-end=\"1273\">The process executes its critical section.<\/li>\n<\/ul>\n<h4 data-start=\"1275\" data-end=\"1300\"><strong data-start=\"1280\" data-end=\"1300\">4. Exit Section:<\/strong><\/h4>\n<ul data-start=\"1304\" data-end=\"1396\">\n<li data-start=\"1304\" data-end=\"1341\">The process sets <code data-start=\"1323\" data-end=\"1340\">want[i] = false<\/code>.<\/li>\n<li data-start=\"1345\" data-end=\"1396\">Gives the turn to the other process (<code data-start=\"1384\" data-end=\"1394\">turn = j<\/code>).<\/li>\n<\/ul>\n<h3 data-start=\"1403\" data-end=\"1457\"><strong data-start=\"1406\" data-end=\"1457\">Dekker&#8217;s Algorithm (Code Implementation in C++)<\/strong><\/h3>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre language-cpp\"><code class=\"!whitespace-pre language-cpp\"><span class=\"hljs-meta\">#<span class=\"hljs-keyword\">include<\/span><\/span> <span class=\"hljs-string\">&lt;iostream&gt;<\/span><br \/>\n<span class=\"hljs-meta\">#<span class=\"hljs-keyword\">include<\/span><\/span> <span class=\"hljs-string\">&lt;thread&gt;<\/span><br \/>\n<span class=\"hljs-meta\">#<span class=\"hljs-keyword\">include<\/span><\/span> <span class=\"hljs-string\">&lt;atomic&gt;<\/span><\/code><\/code><span class=\"hljs-keyword\">using<\/span> <span class=\"hljs-keyword\">namespace<\/span> std;<code class=\"!whitespace-pre language-cpp\"><code class=\"!whitespace-pre language-cpp\"><\/code><\/code>atomic&lt;<span class=\"hljs-type\">bool<\/span>&gt; want[<span class=\"hljs-number\">2<\/span>] = {<span class=\"hljs-literal\">false<\/span>, <span class=\"hljs-literal\">false<\/span>};<br \/>\natomic&lt;<span class=\"hljs-type\">int<\/span>&gt; turn = <span class=\"hljs-number\">0<\/span>;<code class=\"!whitespace-pre language-cpp\"><code class=\"!whitespace-pre language-cpp\"><\/code><\/code><span class=\"hljs-function\"><span class=\"hljs-type\">void<\/span><\/span> <span class=\"hljs-title\">process<\/span><span class=\"hljs-params\">(<span class=\"hljs-type\">int<\/span><\/span> i) {<br \/>\n<span class=\"hljs-type\">int<\/span> j = <span class=\"hljs-number\">1<\/span> &#8211; i; <span class=\"hljs-comment\">\/\/ The other process<\/span><br \/>\n<span class=\"hljs-keyword\">for<\/span> (<span class=\"hljs-type\">int<\/span> k = <span class=\"hljs-number\">0<\/span>; k &lt; <span class=\"hljs-number\">5<\/span>; k++) { <span class=\"hljs-comment\">\/\/ Simulating multiple iterations<\/span><br \/>\nwant[i] = <span class=\"hljs-literal\">true<\/span>;<br \/>\n<span class=\"hljs-keyword\">while<\/span> (want[j]) {<br \/>\n<span class=\"hljs-keyword\">if<\/span> (turn != i) {<br \/>\nwant[i] = <span class=\"hljs-literal\">false<\/span>;<br \/>\n<span class=\"hljs-keyword\">while<\/span> (turn != i); <span class=\"hljs-comment\">\/\/ Busy wait<\/span><br \/>\nwant[i] = <span class=\"hljs-literal\">true<\/span>;<br \/>\n}<br \/>\n}<\/p>\n<p><code class=\"!whitespace-pre language-cpp\"><code class=\"!whitespace-pre language-cpp\"><\/code><\/code><span class=\"hljs-comment\">\/\/ Critical Section<\/span><br \/>\ncout &lt;&lt; <span class=\"hljs-string\">&#8220;Process &#8220;<\/span> &lt;&lt; i &lt;&lt; <span class=\"hljs-string\">&#8221; is in the Critical Section.\\n&#8221;<\/span>;<\/p>\n<p><code class=\"!whitespace-pre language-cpp\"><code class=\"!whitespace-pre language-cpp\"><\/code><\/code><span class=\"hljs-comment\">\/\/ Exit Section<\/span><br \/>\nturn = j;<br \/>\nwant[i] = <span class=\"hljs-literal\">false<\/span>;<br \/>\n}<br \/>\n}<\/p>\n<p><code class=\"!whitespace-pre language-cpp\"><code class=\"!whitespace-pre language-cpp\"><\/code><\/code><span class=\"hljs-function\"><span class=\"hljs-type\">int<\/span><\/span> <span class=\"hljs-title\">main<\/span><span class=\"hljs-params\">()<\/span> {<br \/>\n<span class=\"hljs-function\">thread <span class=\"hljs-title\">t1<\/span><\/span><span class=\"hljs-params\">(process, <span class=\"hljs-number\">0<\/span><\/span>);<br \/>\n<span class=\"hljs-function\">thread <span class=\"hljs-title\">t2<\/span><\/span><span class=\"hljs-params\">(process, <span class=\"hljs-number\">1<\/span><\/span>);<\/p>\n<p><code class=\"!whitespace-pre language-cpp\"><code class=\"!whitespace-pre language-cpp\"><\/code><\/code>t1.<span class=\"hljs-built_in\">join<\/span>();<br \/>\nt2.<span class=\"hljs-built_in\">join<\/span>();<\/p>\n<p><code class=\"!whitespace-pre language-cpp\"><code class=\"!whitespace-pre language-cpp\"><\/code><\/code><span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-number\">0<\/span>;<br \/>\n}<\/p>\n<\/div>\n<\/div>\n<h3 data-start=\"2269\" data-end=\"2312\"><strong data-start=\"2272\" data-end=\"2312\">Key Properties of Dekker\u2019s Algorithm<\/strong><\/h3>\n<p data-start=\"2313\" data-end=\"2550\"><strong data-start=\"2315\" data-end=\"2335\">Mutual Exclusion<\/strong> \u2013 Only one process enters the critical section at a time.<br data-start=\"2393\" data-end=\"2396\" \/><strong data-start=\"2398\" data-end=\"2410\">Progress<\/strong> \u2013 If no process is in CS, one can enter without indefinite waiting.<br data-start=\"2478\" data-end=\"2481\" \/><strong data-start=\"2483\" data-end=\"2502\">Bounded Waiting<\/strong> \u2013 No process suffers indefinite postponement.<\/p>\n<h3 data-start=\"2557\" data-end=\"2575\"><strong data-start=\"2560\" data-end=\"2575\">Limitations<\/strong><\/h3>\n<p data-start=\"2576\" data-end=\"2727\">\u00a0Works only for <strong data-start=\"2594\" data-end=\"2601\">two<\/strong> processes.<br data-start=\"2612\" data-end=\"2615\" \/>\u00a0Uses <strong data-start=\"2623\" data-end=\"2639\">busy waiting<\/strong> (inefficient CPU utilization).<br data-start=\"2670\" data-end=\"2673\" \/>\u00a0Not suitable for modern multi-core architectures.<\/p>\n<p data-start=\"2729\" data-end=\"2854\" data-is-last-node=\"\" data-is-only-node=\"\">Would you like an explanation of an alternative algorithm like <strong data-start=\"2792\" data-end=\"2816\">Peterson&#8217;s Algorithm<\/strong> or <strong data-start=\"2820\" data-end=\"2850\">Lamport\u2019s Bakery Algorithm<\/strong>?<\/p>\n<h3 data-start=\"2729\" data-end=\"2854\"><a href=\"https:\/\/www.cs.ucf.edu\/courses\/cop4600\/sum2007\/files\/os_lec_09_concurrency_sw.pdf\" target=\"_blank\" rel=\"noopener\">Process Synchronization Two Process Solution) (Algo-3) l Decker&#8217;s Algorithm.<\/a><\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/gurunanakcollege.edu.in\/files\/science\/computer-science\/BCA_Kiruthiga_OS_process-sync.pdf\" target=\"_blank\" rel=\"noopener\">Process Synchronization<\/a><\/h3>\n<h3 data-start=\"0\" data-end=\"86\">\ud83d\udd10 <strong data-start=\"7\" data-end=\"86\">Process Synchronization \u2013 Decker&#8217;s Algorithm (Two Process Solution, Algo-3)<\/strong><\/h3>\n<p data-start=\"88\" data-end=\"339\"><strong data-start=\"88\" data-end=\"110\">Decker&#8217;s Algorithm<\/strong> is a classic software solution for <strong data-start=\"146\" data-end=\"173\">process synchronization<\/strong> between <strong data-start=\"182\" data-end=\"199\">two processes<\/strong>. It was one of the earliest attempts to solve the <strong data-start=\"250\" data-end=\"278\">critical section problem<\/strong> <strong data-start=\"279\" data-end=\"307\">without hardware support<\/strong> (i.e., no atomic test-and-set).<\/p>\n<hr data-start=\"341\" data-end=\"344\" \/>\n<h2 data-start=\"346\" data-end=\"383\">\ud83e\udde0 <strong data-start=\"352\" data-end=\"383\">Why Use Decker&#8217;s Algorithm?<\/strong><\/h2>\n<p data-start=\"384\" data-end=\"522\">To ensure that <strong data-start=\"399\" data-end=\"416\">two processes<\/strong> (say, P0 and P1) <strong data-start=\"434\" data-end=\"491\">do not enter their critical sections at the same time<\/strong>, avoiding <strong data-start=\"502\" data-end=\"521\">race conditions<\/strong>.<\/p>\n<p data-start=\"524\" data-end=\"583\">It satisfies the <strong data-start=\"541\" data-end=\"582\">three requirements of synchronization<\/strong>:<\/p>\n<ol data-start=\"584\" data-end=\"646\">\n<li data-start=\"584\" data-end=\"607\">\n<p data-start=\"587\" data-end=\"607\"><strong data-start=\"587\" data-end=\"607\">Mutual Exclusion<\/strong><\/p>\n<\/li>\n<li data-start=\"608\" data-end=\"623\">\n<p data-start=\"611\" data-end=\"623\"><strong data-start=\"611\" data-end=\"623\">Progress<\/strong><\/p>\n<\/li>\n<li data-start=\"624\" data-end=\"646\">\n<p data-start=\"627\" data-end=\"646\"><strong data-start=\"627\" data-end=\"646\">Bounded Waiting<\/strong><\/p>\n<\/li>\n<\/ol>\n<hr data-start=\"648\" data-end=\"651\" \/>\n<h2 data-start=\"653\" data-end=\"674\">\u2699\ufe0f <strong data-start=\"659\" data-end=\"674\">Basic Idea:<\/strong><\/h2>\n<ul data-start=\"675\" data-end=\"866\">\n<li data-start=\"675\" data-end=\"761\">\n<p data-start=\"677\" data-end=\"761\">Each process indicates its <strong data-start=\"704\" data-end=\"717\">intention<\/strong> to enter the critical section using a flag.<\/p>\n<\/li>\n<li data-start=\"762\" data-end=\"866\">\n<p data-start=\"764\" data-end=\"866\">A shared variable <code data-start=\"782\" data-end=\"788\">turn<\/code> decides which process gets the turn when both want to enter at the same time.<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"868\" data-end=\"871\" \/>\n<h2 data-start=\"873\" data-end=\"898\">\ud83d\udd27 <strong data-start=\"879\" data-end=\"898\">Variables Used:<\/strong><\/h2>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none rounded-t-[5px]\">c<\/div>\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-sidebar-surface-primary text-token-text-secondary dark:bg-token-main-surface-secondary flex items-center rounded-sm px-2 font-sans text-xs\"><button class=\"flex gap-1 items-center select-none px-4 py-1\" aria-label=\"Copy\">Copy<\/button><span class=\"\" data-state=\"closed\"><button class=\"flex items-center gap-1 px-4 py-1 select-none\">Edit<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre! language-c\">boolean flag[<span class=\"hljs-number\">2<\/span>];  <span class=\"hljs-comment\">\/\/ flag[i] = true if process Pi wants to enter critical section<\/span><br \/>\n<span class=\"hljs-type\">int<\/span> turn;         <span class=\"hljs-comment\">\/\/ whose turn it is (0 or 1)<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<hr data-start=\"1039\" data-end=\"1042\" \/>\n<h2 data-start=\"1044\" data-end=\"1095\">\ud83e\uddfe <strong data-start=\"1050\" data-end=\"1095\">Algorithm (for both processes P0 and P1):<\/strong><\/h2>\n<h3 data-start=\"1097\" data-end=\"1141\">\ud83d\udd01 <strong data-start=\"1104\" data-end=\"1141\">Code for Process Pi (i = 0 or 1):<\/strong><\/h3>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none rounded-t-[5px]\">c<\/div>\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-sidebar-surface-primary text-token-text-secondary dark:bg-token-main-surface-secondary flex items-center rounded-sm px-2 font-sans text-xs\"><button class=\"flex gap-1 items-center select-none px-4 py-1\" aria-label=\"Copy\">Copy<\/button><span class=\"\" data-state=\"closed\"><button class=\"flex items-center gap-1 px-4 py-1 select-none\">Edit<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre! language-c\"><code class=\"whitespace-pre! language-c\"><span class=\"hljs-keyword\">do<\/span> {<br \/>\nflag[i] = <span class=\"hljs-literal\">true<\/span>;<br \/>\n<span class=\"hljs-keyword\">while<\/span> (flag[j]) {<br \/>\n<span class=\"hljs-keyword\">if<\/span> (turn != i) {<br \/>\nflag[i] = <span class=\"hljs-literal\">false<\/span>;<br \/>\n<span class=\"hljs-keyword\">while<\/span> (turn != i)<br \/>\n; <span class=\"hljs-comment\">\/\/ busy wait<\/span><br \/>\nflag[i] = <span class=\"hljs-literal\">true<\/span>;<br \/>\n}<br \/>\n}<\/code><\/code><span class=\"hljs-comment\">\/\/ Critical Section (CS)<\/span><br \/>\n<span class=\"hljs-comment\">\/\/ Perform shared data operations here<\/span><code class=\"whitespace-pre! language-c\"><code class=\"whitespace-pre! language-c\"><\/code><\/code>turn = j;<br \/>\nflag[i] = <span class=\"hljs-literal\">false<\/span>;<\/p>\n<p><code class=\"whitespace-pre! language-c\"><code class=\"whitespace-pre! language-c\"><\/code><\/code><span class=\"hljs-comment\">\/\/ Remainder Section<\/span><br \/>\n} <span class=\"hljs-keyword\">while<\/span> (<span class=\"hljs-literal\">true<\/span>);<\/p>\n<\/div>\n<\/div>\n<p data-start=\"1510\" data-end=\"1516\">Where:<\/p>\n<ul data-start=\"1517\" data-end=\"1589\">\n<li data-start=\"1517\" data-end=\"1554\">\n<p data-start=\"1519\" data-end=\"1554\"><code data-start=\"1519\" data-end=\"1522\">i<\/code> is the current process (0 or 1)<\/p>\n<\/li>\n<li data-start=\"1555\" data-end=\"1589\">\n<p data-start=\"1557\" data-end=\"1589\"><code data-start=\"1557\" data-end=\"1568\">j = 1 - i<\/code> is the other process<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"1591\" data-end=\"1594\" \/>\n<h2 data-start=\"1596\" data-end=\"1618\">\u2705 <strong data-start=\"1601\" data-end=\"1618\">How It Works:<\/strong><\/h2>\n<ol data-start=\"1620\" data-end=\"2057\">\n<li data-start=\"1620\" data-end=\"1686\">\n<p data-start=\"1623\" data-end=\"1686\">Each process sets <code data-start=\"1641\" data-end=\"1657\">flag[i] = true<\/code> to indicate intent to enter.<\/p>\n<\/li>\n<li data-start=\"1687\" data-end=\"1778\">\n<p data-start=\"1690\" data-end=\"1778\">If the other process (<code data-start=\"1712\" data-end=\"1715\">j<\/code>) also wants to enter (<code data-start=\"1738\" data-end=\"1755\">flag[j] == true<\/code>), then <strong data-start=\"1763\" data-end=\"1777\">check turn<\/strong>.<\/p>\n<\/li>\n<li data-start=\"1779\" data-end=\"1857\">\n<p data-start=\"1782\" data-end=\"1857\">If it\u2019s not Pi&#8217;s turn, it backs off by setting <code data-start=\"1829\" data-end=\"1846\">flag[i] = false<\/code> and waits.<\/p>\n<\/li>\n<li data-start=\"1858\" data-end=\"1943\">\n<p data-start=\"1861\" data-end=\"1943\">Once the turn becomes theirs again, it reasserts <code data-start=\"1910\" data-end=\"1926\">flag[i] = true<\/code> and tries again.<\/p>\n<\/li>\n<li data-start=\"1944\" data-end=\"2057\">\n<p data-start=\"1947\" data-end=\"1976\">Upon exiting CS, the process:<\/p>\n<ul data-start=\"1980\" data-end=\"2057\">\n<li data-start=\"1980\" data-end=\"2017\">\n<p data-start=\"1982\" data-end=\"2017\">Gives turn to the other: <code data-start=\"2007\" data-end=\"2017\">turn = j<\/code><\/p>\n<\/li>\n<li data-start=\"2021\" data-end=\"2057\">\n<p data-start=\"2023\" data-end=\"2057\">Resets its flag: <code data-start=\"2040\" data-end=\"2057\">flag[i] = false<\/code><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<hr data-start=\"2059\" data-end=\"2062\" \/>\n<h2 data-start=\"2064\" data-end=\"2082\">\ud83d\udd10 <strong data-start=\"2070\" data-end=\"2082\">Ensures:<\/strong><\/h2>\n<ul data-start=\"2083\" data-end=\"2268\">\n<li data-start=\"2083\" data-end=\"2140\">\n<p data-start=\"2085\" data-end=\"2140\"><strong data-start=\"2085\" data-end=\"2105\">Mutual Exclusion<\/strong>: Only one process in CS at a time.<\/p>\n<\/li>\n<li data-start=\"2141\" data-end=\"2209\">\n<p data-start=\"2143\" data-end=\"2209\"><strong data-start=\"2143\" data-end=\"2155\">Progress<\/strong>: If no process is in CS, decision is based on <code data-start=\"2202\" data-end=\"2208\">turn<\/code>.<\/p>\n<\/li>\n<li data-start=\"2210\" data-end=\"2268\">\n<p data-start=\"2212\" data-end=\"2268\"><strong data-start=\"2212\" data-end=\"2231\">Bounded Waiting<\/strong>: No process is left waiting forever.<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"2270\" data-end=\"2273\" \/>\n<h2 data-start=\"2275\" data-end=\"2293\">\ud83d\udcdd <strong data-start=\"2281\" data-end=\"2293\">Example:<\/strong><\/h2>\n<p data-start=\"2295\" data-end=\"2302\">Assume:<\/p>\n<ul data-start=\"2303\" data-end=\"2345\">\n<li data-start=\"2303\" data-end=\"2332\">\n<p data-start=\"2305\" data-end=\"2332\"><code data-start=\"2305\" data-end=\"2332\">flag[0] = flag[1] = false<\/code><\/p>\n<\/li>\n<li data-start=\"2333\" data-end=\"2345\">\n<p data-start=\"2335\" data-end=\"2345\"><code data-start=\"2335\" data-end=\"2345\">turn = 0<\/code><\/p>\n<\/li>\n<\/ul>\n<p data-start=\"2347\" data-end=\"2378\">If both processes try to enter:<\/p>\n<ul data-start=\"2379\" data-end=\"2551\">\n<li data-start=\"2379\" data-end=\"2412\">\n<p data-start=\"2381\" data-end=\"2412\">Both set their <code data-start=\"2396\" data-end=\"2402\">flag<\/code> to <code data-start=\"2406\" data-end=\"2412\">true<\/code><\/p>\n<\/li>\n<li data-start=\"2413\" data-end=\"2466\">\n<p data-start=\"2415\" data-end=\"2466\">P1 finds <code data-start=\"2424\" data-end=\"2435\">turn != 1<\/code>, backs off (<code data-start=\"2448\" data-end=\"2465\">flag[1] = false<\/code>)<\/p>\n<\/li>\n<li data-start=\"2467\" data-end=\"2481\">\n<p data-start=\"2469\" data-end=\"2481\">P0 enters CS<\/p>\n<\/li>\n<li data-start=\"2482\" data-end=\"2532\">\n<p data-start=\"2484\" data-end=\"2532\">When done, P0 sets <code data-start=\"2503\" data-end=\"2513\">turn = 1<\/code>, <code data-start=\"2515\" data-end=\"2532\">flag[0] = false<\/code><\/p>\n<\/li>\n<li data-start=\"2533\" data-end=\"2551\">\n<p data-start=\"2535\" data-end=\"2551\">Now P1 can enter<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"2553\" data-end=\"2556\" \/>\n<h2 data-start=\"2558\" data-end=\"2580\">\u26a0\ufe0f <strong data-start=\"2564\" data-end=\"2580\">Limitations:<\/strong><\/h2>\n<ul data-start=\"2581\" data-end=\"2706\">\n<li data-start=\"2581\" data-end=\"2615\">\n<p data-start=\"2583\" data-end=\"2615\">Only works for <strong data-start=\"2598\" data-end=\"2615\">two processes<\/strong><\/p>\n<\/li>\n<li data-start=\"2616\" data-end=\"2646\">\n<p data-start=\"2618\" data-end=\"2646\">Not scalable for more than 2<\/p>\n<\/li>\n<li data-start=\"2647\" data-end=\"2706\">\n<p data-start=\"2649\" data-end=\"2706\">Uses <strong data-start=\"2654\" data-end=\"2670\">busy waiting<\/strong> (CPU cycles are wasted during wait)<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"2708\" data-end=\"2711\" \/>\n<h2 data-start=\"2713\" data-end=\"2727\">\ud83e\udde0 Summary:<\/h2>\n<div class=\"_tableContainer_16hzy_1\">\n<div class=\"_tableWrapper_16hzy_14 group flex w-fit flex-col-reverse\">\n<table class=\"w-fit min-w-(--thread-content-width)\" data-start=\"2729\" data-end=\"3183\">\n<thead data-start=\"2729\" data-end=\"2793\">\n<tr data-start=\"2729\" data-end=\"2793\">\n<th data-start=\"2729\" data-end=\"2753\" data-col-size=\"sm\">Feature<\/th>\n<th data-start=\"2753\" data-end=\"2793\" data-col-size=\"sm\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"2859\" data-end=\"3183\">\n<tr data-start=\"2859\" data-end=\"2923\">\n<td data-start=\"2859\" data-end=\"2883\" data-col-size=\"sm\">Process Support<\/td>\n<td data-start=\"2883\" data-end=\"2923\" data-col-size=\"sm\">Only 2 processes<\/td>\n<\/tr>\n<tr data-start=\"2924\" data-end=\"2988\">\n<td data-start=\"2924\" data-end=\"2948\" data-col-size=\"sm\">Main Control Variable<\/td>\n<td data-start=\"2948\" data-end=\"2988\" data-col-size=\"sm\"><code data-start=\"2950\" data-end=\"2959\">flag[2]<\/code> and <code data-start=\"2964\" data-end=\"2970\">turn<\/code><\/td>\n<\/tr>\n<tr data-start=\"2989\" data-end=\"3053\">\n<td data-start=\"2989\" data-end=\"3013\" data-col-size=\"sm\">CS Safety<\/td>\n<td data-start=\"3013\" data-end=\"3053\" data-col-size=\"sm\">Yes (ensures mutual exclusion)<\/td>\n<\/tr>\n<tr data-start=\"3054\" data-end=\"3119\">\n<td data-start=\"3054\" data-end=\"3078\" data-col-size=\"sm\">Fairness<\/td>\n<td data-start=\"3078\" data-end=\"3119\" data-col-size=\"sm\">Yes (bounded waiting, alternates turn)<\/td>\n<\/tr>\n<tr data-start=\"3120\" data-end=\"3183\">\n<td data-start=\"3120\" data-end=\"3144\" data-col-size=\"sm\">Type<\/td>\n<td data-start=\"3144\" data-end=\"3183\" data-col-size=\"sm\">Software-based<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"sticky end-(--thread-content-margin) h-0 self-end select-none\">\n<div class=\"absolute end-0 flex items-end\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr data-start=\"3185\" data-end=\"3188\" \/>\n<p data-start=\"3190\" data-end=\"3222\">If you&#8217;d like, I can also share:<\/p>\n<ul data-start=\"3223\" data-end=\"3339\">\n<li data-start=\"3223\" data-end=\"3254\">\n<p data-start=\"3225\" data-end=\"3254\">\ud83d\udccb <strong data-start=\"3228\" data-end=\"3254\">Annotated Code Example<\/strong><\/p>\n<\/li>\n<li data-start=\"3255\" data-end=\"3300\">\n<p data-start=\"3257\" data-end=\"3300\">\ud83d\udcca <strong data-start=\"3260\" data-end=\"3300\">Comparison with Peterson\u2019s Algorithm<\/strong><\/p>\n<\/li>\n<li data-start=\"3301\" data-end=\"3339\">\n<p data-start=\"3303\" data-end=\"3339\">\ud83c\udf93 <strong data-start=\"3306\" data-end=\"3339\">MCQ Quiz for GATE Preparation<\/strong><\/p>\n<\/li>\n<\/ul>\n<p data-start=\"3341\" data-end=\"3369\" data-is-last-node=\"\" data-is-only-node=\"\">Shall we continue with that?<\/p>\n<h3 data-start=\"3341\" data-end=\"3369\"><a href=\"https:\/\/home.adelphi.edu\/~siegfried\/cs453\/453l6.pdf\" target=\"_blank\" rel=\"noopener\">Process Synchronization Two Process Solution) (Algo-3) l Decker&#8217;s Algorithm.<\/a><\/h3>\n","protected":false},"excerpt":{"rendered":"<p>Process Synchronization Two Process Solution) (Algo-3) l Decker&#8217;s Algorithm. [fvplayer id=&#8221;362&#8243;] Dekker\u2019s Algorithm \u2013 Process Synchronization (Two-Process Solution) (Algo-3) Dekker\u2019s Algorithm is one of the earliest known solutions to the critical section problem for two processes running in a shared memory environment. It ensures mutual exclusion, progress, and bounded waiting. Problem: Process Synchronization When multiple [&hellip;]<\/p>\n","protected":false},"author":66,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[78],"tags":[],"class_list":["post-3344","post","type-post","status-publish","format-standard","hentry","category-operating-system"],"_links":{"self":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts\/3344","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/users\/66"}],"replies":[{"embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/comments?post=3344"}],"version-history":[{"count":0,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts\/3344\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/media?parent=3344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/categories?post=3344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/tags?post=3344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}