{"id":3345,"date":"2025-06-05T04:21:46","date_gmt":"2025-06-05T04:21:46","guid":{"rendered":"https:\/\/diznr.com\/?p=3345"},"modified":"2025-06-05T04:21:46","modified_gmt":"2025-06-05T04:21:46","slug":"process-synchronization-two-process-solution-algo-2-deadlock-concept-concept-flag","status":"publish","type":"post","link":"https:\/\/www.reilsolar.com\/pdf\/process-synchronization-two-process-solution-algo-2-deadlock-concept-concept-flag\/","title":{"rendered":"Process Synchronization Two process Solution (Algo-2) Deadlock Concept, Flag concept."},"content":{"rendered":"<p>Process Synchronization Two process Solution (Algo-2) Deadlock Concept , Flag concept.<\/p>\n<p>[fvplayer id=&#8221;363&#8243;]<\/p>\n<h3 data-start=\"0\" data-end=\"89\"><strong data-start=\"2\" data-end=\"87\">Process Synchronization \u2013 Two Process Solution (Algo-2) | Deadlock &amp; Flag Concept<\/strong><\/h3>\n<h3 data-start=\"91\" data-end=\"140\"><strong data-start=\"94\" data-end=\"140\">\u00a0Introduction to Process Synchronization<\/strong><\/h3>\n<p data-start=\"141\" data-end=\"371\">Process Synchronization is a mechanism to ensure that multiple processes can execute in a way that avoids inconsistencies and conflicts when accessing shared resources. One of the key challenges in synchronization is <strong data-start=\"358\" data-end=\"370\">deadlock<\/strong>.<\/p>\n<h3 data-start=\"373\" data-end=\"417\"><strong data-start=\"376\" data-end=\"417\">\u00a0Two-Process Solution (Algorithm-2)<\/strong><\/h3>\n<p data-start=\"418\" data-end=\"571\">The Two-Process Solution for synchronization ensures mutual exclusion, progress, and bounded waiting. It typically uses <strong data-start=\"538\" data-end=\"547\">flags<\/strong> and <strong data-start=\"552\" data-end=\"570\">turn variables<\/strong>.<\/p>\n<h3 data-start=\"573\" data-end=\"625\"><strong data-start=\"577\" data-end=\"625\">\u00a0Algorithm-2 (Flag Concept Based Approach)<\/strong><\/h3>\n<p data-start=\"626\" data-end=\"728\">This method relies on <strong data-start=\"648\" data-end=\"661\">two flags<\/strong> to indicate whether a process wants to enter the critical section.<\/p>\n<h3 data-start=\"730\" data-end=\"753\"><strong data-start=\"734\" data-end=\"753\">\u00a0Assumptions:<\/strong><\/h3>\n<ul data-start=\"754\" data-end=\"934\">\n<li data-start=\"754\" data-end=\"795\">There are <strong data-start=\"766\" data-end=\"783\">two processes<\/strong>, P1 and P2.<\/li>\n<li data-start=\"796\" data-end=\"871\">Each process sets its <strong data-start=\"820\" data-end=\"828\">flag<\/strong> to indicate entry to the critical section.<\/li>\n<li data-start=\"872\" data-end=\"934\">The process checks the other process\u2019s flag before entering.<\/li>\n<\/ul>\n<h3 data-start=\"936\" data-end=\"970\"><strong data-start=\"940\" data-end=\"970\">\u00a0Algorithm (Using Flags)<\/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-c\"><code class=\"!whitespace-pre language-c\"><span class=\"hljs-comment\">\/\/ Shared Variables<\/span><br \/>\nboolean flag[<span class=\"hljs-number\">2<\/span>] = {<span class=\"hljs-literal\">false<\/span>, <span class=\"hljs-literal\">false<\/span>};  <span class=\"hljs-comment\">\/\/ Flags for P1 and P2<\/span><\/code><\/code>Process P1:<br \/>\n<span class=\"hljs-keyword\">while<\/span> (<span class=\"hljs-literal\">true<\/span>) {<br \/>\nflag[<span class=\"hljs-number\">0<\/span>] = <span class=\"hljs-literal\">true<\/span>; <span class=\"hljs-comment\">\/\/ P1 wants to enter the critical section<\/span><br \/>\n<span class=\"hljs-keyword\">while<\/span> (flag[<span class=\"hljs-number\">1<\/span>]); <span class=\"hljs-comment\">\/\/ Wait if P2 is in the critical section<\/span><code class=\"!whitespace-pre language-c\"><code class=\"!whitespace-pre language-c\"><\/code><\/code><span class=\"hljs-comment\">\/\/ Critical Section (CS)<\/span><code class=\"!whitespace-pre language-c\"><code class=\"!whitespace-pre language-c\"><\/code><\/code>flag[<span class=\"hljs-number\">0<\/span>] = <span class=\"hljs-literal\">false<\/span>; <span class=\"hljs-comment\">\/\/ Exit CS<\/span><br \/>\n<span class=\"hljs-comment\">\/\/ Remainder Section<\/span><br \/>\n}<\/p>\n<p><code class=\"!whitespace-pre language-c\"><code class=\"!whitespace-pre language-c\"><\/code><\/code>Process P2:<br \/>\n<span class=\"hljs-keyword\">while<\/span> (<span class=\"hljs-literal\">true<\/span>) {<br \/>\nflag[<span class=\"hljs-number\">1<\/span>] = <span class=\"hljs-literal\">true<\/span>; <span class=\"hljs-comment\">\/\/ P2 wants to enter the critical section<\/span><br \/>\n<span class=\"hljs-keyword\">while<\/span> (flag[<span class=\"hljs-number\">0<\/span>]); <span class=\"hljs-comment\">\/\/ Wait if P1 is in the critical section<\/span><\/p>\n<p><code class=\"!whitespace-pre language-c\"><code class=\"!whitespace-pre language-c\"><\/code><\/code><span class=\"hljs-comment\">\/\/ Critical Section (CS)<\/span><\/p>\n<p><code class=\"!whitespace-pre language-c\"><code class=\"!whitespace-pre language-c\"><\/code><\/code>flag[<span class=\"hljs-number\">1<\/span>] = <span class=\"hljs-literal\">false<\/span>; <span class=\"hljs-comment\">\/\/ Exit CS<\/span><br \/>\n<span class=\"hljs-comment\">\/\/ Remainder Section<\/span><br \/>\n}<\/p>\n<\/div>\n<\/div>\n<h3 data-start=\"1557\" data-end=\"1580\"><strong data-start=\"1561\" data-end=\"1580\">\u00a0Explanation:<\/strong><\/h3>\n<ul data-start=\"1581\" data-end=\"1935\">\n<li data-start=\"1581\" data-end=\"1675\">Each process sets its flag (<code data-start=\"1611\" data-end=\"1627\">flag[i] = true<\/code>) before entering the <strong data-start=\"1649\" data-end=\"1674\">Critical Section (CS)<\/strong>.<\/li>\n<li data-start=\"1676\" data-end=\"1751\">It checks whether the other process\u2019s flag is <strong data-start=\"1724\" data-end=\"1732\">true<\/strong>. If yes, it waits.<\/li>\n<li data-start=\"1752\" data-end=\"1830\">If the other process is not in the CS (<code data-start=\"1793\" data-end=\"1810\">flag[j] = false<\/code>), it enters the CS.<\/li>\n<li data-start=\"1831\" data-end=\"1935\">After execution, the process resets its flag (<code data-start=\"1879\" data-end=\"1896\">flag[i] = false<\/code>) and enters the <strong data-start=\"1913\" data-end=\"1934\">Remainder Section<\/strong>.<\/li>\n<\/ul>\n<h3 data-start=\"1937\" data-end=\"1963\"><strong data-start=\"1940\" data-end=\"1963\">\u00a0Deadlock Concept<\/strong><\/h3>\n<p data-start=\"1964\" data-end=\"2068\">A <strong data-start=\"1966\" data-end=\"1978\">deadlock<\/strong> occurs when two or more processes <strong data-start=\"2013\" data-end=\"2034\">wait indefinitely<\/strong> for resources held by each other.<\/p>\n<h3 data-start=\"2070\" data-end=\"2118\"><strong data-start=\"2074\" data-end=\"2118\">\u00a0Can Deadlock Occur in This Algorithm?<\/strong><\/h3>\n<p data-start=\"2119\" data-end=\"2191\">Yes! This algorithm <strong data-start=\"2139\" data-end=\"2146\">can<\/strong> lead to deadlock in the following situation:<\/p>\n<ol data-start=\"2192\" data-end=\"2464\">\n<li data-start=\"2192\" data-end=\"2284\"><strong data-start=\"2195\" data-end=\"2283\">Both P1 and P2 set their flags at the same time (<code data-start=\"2246\" data-end=\"2262\">flag[0] = true<\/code>, <code data-start=\"2264\" data-end=\"2280\">flag[1] = true<\/code>)<\/strong>.<\/li>\n<li data-start=\"2285\" data-end=\"2376\"><strong data-start=\"2288\" data-end=\"2375\">Both enter their respective while loops (<code data-start=\"2331\" data-end=\"2349\">while (flag[1]);<\/code> and <code data-start=\"2354\" data-end=\"2372\">while (flag[0]);<\/code>)<\/strong>.<\/li>\n<li data-start=\"2377\" data-end=\"2464\"><strong data-start=\"2380\" data-end=\"2463\">Now, both are waiting for each other to release the flag, leading to a deadlock<\/strong>.<\/li>\n<\/ol>\n<h3 data-start=\"2466\" data-end=\"2514\"><strong data-start=\"2469\" data-end=\"2514\">\u00a0Avoiding Deadlock: Peterson\u2019s Solution<\/strong><\/h3>\n<p data-start=\"2515\" data-end=\"2626\">Peterson\u2019s Algorithm improves the <strong data-start=\"2549\" data-end=\"2573\">Two-Process Solution<\/strong> by introducing a <strong data-start=\"2591\" data-end=\"2608\">turn variable<\/strong> along with flags.<\/p>\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-c\"><code class=\"!whitespace-pre language-c\">boolean flag[<span class=\"hljs-number\">2<\/span>] = {<span class=\"hljs-literal\">false<\/span>, <span class=\"hljs-literal\">false<\/span>};<br \/>\n<span class=\"hljs-type\">int<\/span> turn = <span class=\"hljs-number\">0<\/span>; <span class=\"hljs-comment\">\/\/ Indicates which process gets priority<\/span><\/code><\/code>Process P1:<br \/>\n<span class=\"hljs-keyword\">while<\/span> (<span class=\"hljs-literal\">true<\/span>) {<br \/>\nflag[<span class=\"hljs-number\">0<\/span>] = <span class=\"hljs-literal\">true<\/span>;<br \/>\nturn = <span class=\"hljs-number\">1<\/span>;<br \/>\n<span class=\"hljs-keyword\">while<\/span> (flag[<span class=\"hljs-number\">1<\/span>] &amp;&amp; turn == <span class=\"hljs-number\">1<\/span>); <span class=\"hljs-comment\">\/\/ Wait if P2 has priority<\/span><code class=\"!whitespace-pre language-c\"><code class=\"!whitespace-pre language-c\"><\/code><\/code><span class=\"hljs-comment\">\/\/ Critical Section<\/span><br \/>\nflag[<span class=\"hljs-number\">0<\/span>] = <span class=\"hljs-literal\">false<\/span>; <span class=\"hljs-comment\">\/\/ Exit CS<\/span><br \/>\n}<code class=\"!whitespace-pre language-c\"><code class=\"!whitespace-pre language-c\"><\/code><\/code>Process P2:<br \/>\n<span class=\"hljs-keyword\">while<\/span> (<span class=\"hljs-literal\">true<\/span>) {<br \/>\nflag[<span class=\"hljs-number\">1<\/span>] = <span class=\"hljs-literal\">true<\/span>;<br \/>\nturn = <span class=\"hljs-number\">0<\/span>;<br \/>\n<span class=\"hljs-keyword\">while<\/span> (flag[<span class=\"hljs-number\">0<\/span>] &amp;&amp; turn == <span class=\"hljs-number\">0<\/span>); <span class=\"hljs-comment\">\/\/ Wait if P1 has priority<\/span><\/p>\n<p><code class=\"!whitespace-pre language-c\"><code class=\"!whitespace-pre language-c\"><\/code><\/code><span class=\"hljs-comment\">\/\/ Critical Section<\/span><br \/>\nflag[<span class=\"hljs-number\">1<\/span>] = <span class=\"hljs-literal\">false<\/span>; <span class=\"hljs-comment\">\/\/ Exit CS<\/span><br \/>\n}<\/p>\n<\/div>\n<\/div>\n<h3 data-start=\"3090\" data-end=\"3141\"><strong data-start=\"3094\" data-end=\"3141\">\u00a0Why is Peterson\u2019s Solution Deadlock-Free?<\/strong><\/h3>\n<ul data-start=\"3142\" data-end=\"3292\">\n<li data-start=\"3142\" data-end=\"3230\">If both processes want to enter, the <strong data-start=\"3181\" data-end=\"3229\">turn variable ensures only one gets priority<\/strong>.<\/li>\n<li data-start=\"3231\" data-end=\"3292\">This prevents both from waiting indefinitely on each other.<\/li>\n<\/ul>\n<h3 data-start=\"3294\" data-end=\"3314\"><strong data-start=\"3297\" data-end=\"3314\">Conclusion<\/strong><\/h3>\n<ul data-start=\"3315\" data-end=\"3602\">\n<li data-start=\"3315\" data-end=\"3420\"><strong data-start=\"3317\" data-end=\"3347\">Algorithm-2 (Flag Concept)<\/strong> can cause <strong data-start=\"3358\" data-end=\"3370\">deadlock<\/strong> if both processes set their flags simultaneously.<\/li>\n<li data-start=\"3421\" data-end=\"3494\"><strong data-start=\"3423\" data-end=\"3447\">Peterson\u2019s Algorithm<\/strong> eliminates deadlock using a <strong data-start=\"3476\" data-end=\"3493\">turn variable<\/strong>.<\/li>\n<li data-start=\"3495\" data-end=\"3602\">Process Synchronization is essential in <strong data-start=\"3537\" data-end=\"3601\">operating systems, multi-threading, and concurrent computing<\/strong>.<\/li>\n<\/ul>\n<p data-start=\"3604\" data-end=\"3674\" data-is-last-node=\"\" data-is-only-node=\"\">\u00a0<strong data-start=\"3607\" data-end=\"3674\" data-is-last-node=\"\">Would you like more details on Deadlock Prevention &amp; Avoidance?<\/strong><\/p>\n<h3 data-start=\"3604\" data-end=\"3674\"><a href=\"https:\/\/gurunanakcollege.edu.in\/files\/science\/computer-science\/BCA_Kiruthiga_OS_process-sync.pdf\" target=\"_blank\" rel=\"noopener\">Process Synchronization Two process Solution (Algo-2) Deadlock Concept, Flag concept.<\/a><\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/cc.ee.ntu.edu.tw\/~farn\/courses\/OS\/slides\/ch06.pdf\" target=\"_blank\" rel=\"noopener\">Chapter 6: Synchronization<\/a><\/h3>\n<p data-start=\"0\" data-end=\"187\">You&#8217;re referring to <strong data-start=\"20\" data-end=\"47\">Process Synchronization<\/strong> in operating systems \u2014 specifically the <strong data-start=\"88\" data-end=\"126\">two-process solution (Algorithm 2)<\/strong> and how it relates to <strong data-start=\"149\" data-end=\"161\">deadlock<\/strong> and the use of <strong data-start=\"177\" data-end=\"186\">flags<\/strong>.<\/p>\n<p data-start=\"189\" data-end=\"231\">Let&#8217;s break it down clearly and concisely.<\/p>\n<hr data-start=\"233\" data-end=\"236\" \/>\n<h3 data-start=\"238\" data-end=\"283\">\u2705 <strong data-start=\"244\" data-end=\"283\">Background: Process Synchronization<\/strong><\/h3>\n<p data-start=\"284\" data-end=\"517\">When two or more processes access <strong data-start=\"318\" data-end=\"338\">shared resources<\/strong> (e.g., a shared variable), there&#8217;s a need to <strong data-start=\"384\" data-end=\"399\">synchronize<\/strong> them to avoid race conditions. <strong data-start=\"431\" data-end=\"451\">Mutual exclusion<\/strong> ensures only one process accesses the critical section at a time.<\/p>\n<hr data-start=\"519\" data-end=\"522\" \/>\n<h3 data-start=\"524\" data-end=\"587\">\ud83d\udd39 <strong data-start=\"531\" data-end=\"587\">Peterson\u2019s Algorithm (Two-Process Solution &#8211; Algo 2)<\/strong><\/h3>\n<p data-start=\"589\" data-end=\"746\">This is a <strong data-start=\"599\" data-end=\"621\">classical solution<\/strong> for the <strong data-start=\"630\" data-end=\"650\">mutual exclusion<\/strong> problem for <strong data-start=\"663\" data-end=\"680\">two processes<\/strong> (<code data-start=\"682\" data-end=\"686\">P0<\/code> and <code data-start=\"691\" data-end=\"695\">P1<\/code>) using <strong data-start=\"703\" data-end=\"711\">flag<\/strong> variables and a <strong data-start=\"728\" data-end=\"736\">turn<\/strong> variable.<\/p>\n<h4 data-start=\"748\" data-end=\"761\">\ud83e\udde0 Idea:<\/h4>\n<p data-start=\"762\" data-end=\"899\">Each process indicates its intention to enter the critical section using a flag and uses a <code data-start=\"853\" data-end=\"859\">turn<\/code> variable to decide who gets to proceed.<\/p>\n<h4 data-start=\"901\" data-end=\"938\">\ud83e\uddfe Code (in C-style pseudocode):<\/h4>\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-type\">bool<\/span> flag[<span class=\"hljs-number\">2<\/span>];     <span class=\"hljs-comment\">\/\/ flag[0] for P0, flag[1] for P1<\/span><br \/>\n<span class=\"hljs-type\">int<\/span> turn;         <span class=\"hljs-comment\">\/\/ shared variable<\/span><\/code><\/code><span class=\"hljs-comment\">\/\/ Code for process Pi (i = 0 or 1)<\/span><br \/>\nflag[i] = <span class=\"hljs-literal\">true<\/span>;<br \/>\nturn = <span class=\"hljs-number\">1<\/span> &#8211; i;<br \/>\n<span class=\"hljs-keyword\">while<\/span> (flag[<span class=\"hljs-number\">1<\/span> &#8211; i] &amp;&amp; turn == <span class=\"hljs-number\">1<\/span> &#8211; i)<br \/>\n; <span class=\"hljs-comment\">\/\/ busy wait (do nothing)<\/span><code class=\"whitespace-pre! language-c\"><code class=\"whitespace-pre! language-c\"><\/code><\/code><span class=\"hljs-comment\">\/\/ &#8212;- Critical Section &#8212;-<\/span><\/p>\n<p><code class=\"whitespace-pre! language-c\"><code class=\"whitespace-pre! language-c\"><\/code><\/code><span class=\"hljs-comment\">\/\/ Exit section<\/span><br \/>\nflag[i] = <span class=\"hljs-literal\">false<\/span>;<\/p>\n<\/div>\n<\/div>\n<hr data-start=\"1240\" data-end=\"1243\" \/>\n<h3 data-start=\"1245\" data-end=\"1268\">\ud83d\udd10 <strong data-start=\"1252\" data-end=\"1268\">Key Concepts<\/strong><\/h3>\n<ul data-start=\"1270\" data-end=\"1533\">\n<li data-start=\"1270\" data-end=\"1384\">\n<p data-start=\"1272\" data-end=\"1384\"><strong data-start=\"1272\" data-end=\"1288\">Flag Concept<\/strong>:<br data-start=\"1289\" data-end=\"1292\" \/>Each process sets its flag to <code data-start=\"1324\" data-end=\"1330\">true<\/code> to indicate a <strong data-start=\"1345\" data-end=\"1362\">wish to enter<\/strong> the critical section.<\/p>\n<\/li>\n<li data-start=\"1388\" data-end=\"1533\">\n<p data-start=\"1390\" data-end=\"1533\"><strong data-start=\"1390\" data-end=\"1407\">Turn Variable<\/strong>:<br data-start=\"1408\" data-end=\"1411\" \/>This gives <strong data-start=\"1424\" data-end=\"1436\">priority<\/strong> to the other process. If both processes want to enter, the one that doesn&#8217;t have the turn waits.<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"1535\" data-end=\"1538\" \/>\n<h3 data-start=\"1540\" data-end=\"1575\">\u26a0\ufe0f <strong data-start=\"1547\" data-end=\"1575\">Deadlock in Algorithm 2?<\/strong><\/h3>\n<p data-start=\"1576\" data-end=\"1631\"><strong data-start=\"1576\" data-end=\"1582\">No<\/strong>, this algorithm <strong data-start=\"1599\" data-end=\"1630\">does not result in deadlock<\/strong>.<\/p>\n<h4 data-start=\"1633\" data-end=\"1644\">\u2705 Why?<\/h4>\n<p data-start=\"1645\" data-end=\"1701\">Both processes <strong data-start=\"1660\" data-end=\"1692\">cannot be stuck indefinitely<\/strong> because:<\/p>\n<ul data-start=\"1702\" data-end=\"1901\">\n<li data-start=\"1702\" data-end=\"1807\">\n<p data-start=\"1704\" data-end=\"1807\">If <code data-start=\"1707\" data-end=\"1711\">P0<\/code> and <code data-start=\"1716\" data-end=\"1720\">P1<\/code> both set their flags to true, then the <code data-start=\"1760\" data-end=\"1766\">turn<\/code> variable determines who gets to proceed.<\/p>\n<\/li>\n<li data-start=\"1808\" data-end=\"1901\">\n<p data-start=\"1810\" data-end=\"1901\">The other process spins in the while loop until the first one finishes and resets its flag.<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"1903\" data-end=\"1916\">This ensures:<\/p>\n<ul data-start=\"1917\" data-end=\"1994\">\n<li data-start=\"1917\" data-end=\"1939\">\n<p data-start=\"1919\" data-end=\"1939\"><strong data-start=\"1919\" data-end=\"1939\">Mutual Exclusion<\/strong><\/p>\n<\/li>\n<li data-start=\"1940\" data-end=\"1957\">\n<p data-start=\"1942\" data-end=\"1957\"><strong data-start=\"1942\" data-end=\"1957\">No Deadlock<\/strong><\/p>\n<\/li>\n<li data-start=\"1958\" data-end=\"1972\">\n<p data-start=\"1960\" data-end=\"1972\"><strong data-start=\"1960\" data-end=\"1972\">Progress<\/strong><\/p>\n<\/li>\n<li data-start=\"1973\" data-end=\"1994\">\n<p data-start=\"1975\" data-end=\"1994\"><strong data-start=\"1975\" data-end=\"1994\">Bounded Waiting<\/strong><\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"1996\" data-end=\"1999\" \/>\n<h3 data-start=\"2001\" data-end=\"2039\">\ud83e\uddea Important Properties Satisfied:<\/h3>\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=\"2041\" data-end=\"2282\">\n<thead data-start=\"2041\" data-end=\"2076\">\n<tr data-start=\"2041\" data-end=\"2076\">\n<th data-start=\"2041\" data-end=\"2062\" data-col-size=\"sm\">Property<\/th>\n<th data-start=\"2062\" data-end=\"2076\" data-col-size=\"sm\">Satisfied?<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"2113\" data-end=\"2282\">\n<tr data-start=\"2113\" data-end=\"2147\">\n<td data-start=\"2113\" data-end=\"2134\" data-col-size=\"sm\">Mutual Exclusion<\/td>\n<td data-col-size=\"sm\" data-start=\"2134\" data-end=\"2147\">\u2705 Yes<\/td>\n<\/tr>\n<tr data-start=\"2148\" data-end=\"2182\">\n<td data-start=\"2148\" data-end=\"2169\" data-col-size=\"sm\">Deadlock-Free<\/td>\n<td data-col-size=\"sm\" data-start=\"2169\" data-end=\"2182\">\u2705 Yes<\/td>\n<\/tr>\n<tr data-start=\"2183\" data-end=\"2217\">\n<td data-start=\"2183\" data-end=\"2204\" data-col-size=\"sm\">Starvation-Free<\/td>\n<td data-col-size=\"sm\" data-start=\"2204\" data-end=\"2217\">\u2705 Yes<\/td>\n<\/tr>\n<tr data-start=\"2218\" data-end=\"2282\">\n<td data-start=\"2218\" data-end=\"2239\" data-col-size=\"sm\">Busy Waiting<\/td>\n<td data-col-size=\"sm\" data-start=\"2239\" data-end=\"2282\">\u274c Yes (but undesirable in real systems)<\/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=\"2284\" data-end=\"2287\" \/>\n<h3 data-start=\"2289\" data-end=\"2304\">\ud83d\udcda Summary:<\/h3>\n<ul data-start=\"2305\" data-end=\"2549\">\n<li data-start=\"2305\" data-end=\"2376\">\n<p data-start=\"2307\" data-end=\"2376\"><strong data-start=\"2307\" data-end=\"2349\">Two-process solution (Peterson\u2019s Algo)<\/strong> uses <code data-start=\"2355\" data-end=\"2364\">flag[2]<\/code> and <code data-start=\"2369\" data-end=\"2375\">turn<\/code>.<\/p>\n<\/li>\n<li data-start=\"2377\" data-end=\"2448\">\n<p data-start=\"2379\" data-end=\"2448\">Ensures <strong data-start=\"2387\" data-end=\"2407\">mutual exclusion<\/strong>, <strong data-start=\"2409\" data-end=\"2424\">no deadlock<\/strong>, and <strong data-start=\"2430\" data-end=\"2447\">no starvation<\/strong>.<\/p>\n<\/li>\n<li data-start=\"2449\" data-end=\"2549\">\n<p data-start=\"2451\" data-end=\"2549\"><strong data-start=\"2451\" data-end=\"2463\">Deadlock<\/strong> is avoided because the <code data-start=\"2487\" data-end=\"2493\">turn<\/code> mechanism prevents both processes from waiting forever.<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"2551\" data-end=\"2554\" \/>\n<p data-start=\"2556\" data-end=\"2646\" data-is-last-node=\"\" data-is-only-node=\"\">Let me know if you want a diagram, trace table, or extension to N-process synchronization.<\/p>\n<h3 data-start=\"2556\" data-end=\"2646\"><a href=\"https:\/\/www.os-book.com\/OS8\/os8j\/slide-dir\/PDF-dir\/ch6.pdf\" target=\"_blank\" rel=\"noopener\">Process Synchronization Two process Solution (Algo-2) Deadlock Concept, Flag concept.<\/a><\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/web.cs.wpi.edu\/~cs3013\/c07\/lectures\/Section06-Sync.pdf\" target=\"_blank\" rel=\"noopener\">OPERATING SYSTEMS PROCESS SYNCHRONIZATION<\/a><\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/gfgc.karnataka.gov.in\/gfgcmalur\/public\/uploads\/media_to_upload1700646239.pdf\" target=\"_blank\" rel=\"noopener\">Process Synchronization Race Condition: Critical Section &#8230;<\/a><\/h3>\n","protected":false},"excerpt":{"rendered":"<p>Process Synchronization Two process Solution (Algo-2) Deadlock Concept , Flag concept. [fvplayer id=&#8221;363&#8243;] Process Synchronization \u2013 Two Process Solution (Algo-2) | Deadlock &amp; Flag Concept \u00a0Introduction to Process Synchronization Process Synchronization is a mechanism to ensure that multiple processes can execute in a way that avoids inconsistencies and conflicts when accessing shared resources. One of [&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-3345","post","type-post","status-publish","format-standard","hentry","category-operating-system"],"_links":{"self":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts\/3345","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=3345"}],"version-history":[{"count":0,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts\/3345\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/media?parent=3345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/categories?post=3345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/tags?post=3345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}