TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: How does swap instruction handles concurrency in operating system?

1 pointsby shivajikobardanalmost 2 years ago
<p><pre><code> How does this algorithm achieves mutual exclusion, progress and bounded waiting if it does? I realize this is not something simple. I actually have a video course for this which is in Hindi but I am not understanding the concept at all. [code] do { key=true; while(key==true) { swap(&amp;lock,&amp;key); } critical section lock=false; Remainder Section }while(true); void swap(boolean *a, boolean *b) { boolean temp=*a; *a=*b; *b=temp; } [&#x2F;code] How do I prove if it satisfied mutual exclusion, progress and bounded waiting?</code></pre>

1 comment

8chanAnonalmost 2 years ago
It is truly unfortunate that most languages lack a built-in swap instruction. Anyway, as written, your example looks like an infinite loop (Remainder Section would need to force an exit). What is the status of &quot;lock&quot; on entering the top of the loop? If it is &quot;true&quot; then this won&#x27;t work (infinite loop in the while statement).