<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>CS on Cheat Sheet</title><link>/tags/cs/</link><description>Recent content in CS on Cheat Sheet</description><generator>Hugo</generator><language>en</language><atom:link href="/tags/cs/index.xml" rel="self" type="application/rss+xml"/><item><title>CSP (Communicating Sequential Processes) and Channels</title><link>/programming/go/concurrency/csp/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/programming/go/concurrency/csp/</guid><description>&lt;h1 id="csp-communicating-sequential-processes-and-channels"&gt;CSP (Communicating Sequential Processes) and Channels&lt;a class="anchor" href="#csp-communicating-sequential-processes-and-channels"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;One of the most transformative paradigms in concurrent programming originated in 1978 with C.A.R. Hoare&amp;rsquo;s landmark paper, &lt;strong&gt;&amp;ldquo;Communicating Sequential Processes (CSP)&amp;rdquo;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Go adopted CSP theory as a first-class citizen in the language design, shaping today&amp;rsquo;s &lt;strong&gt;Goroutines&lt;/strong&gt; and &lt;strong&gt;Channels&lt;/strong&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="1-what-is-csp"&gt;1. What Is CSP?&lt;a class="anchor" href="#1-what-is-csp"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;In the late 1970s, computer science was intensely focused on structured programming (eliminating &lt;code&gt;goto&lt;/code&gt;) and object-oriented paradigms. Concurrency was rarely treated as a fundamental construct; most concurrency relied on &lt;strong&gt;shared memory with lock synchronization&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>Concurrency Concepts</title><link>/cs/concurrency-and-parallelism/concepts/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/cs/concurrency-and-parallelism/concepts/</guid><description>&lt;h1 id="concurrency-concepts"&gt;Concurrency Concepts&lt;a class="anchor" href="#concurrency-concepts"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;When working with concurrent programming, some of the most fundamental yet frequently conflated concepts are &lt;strong&gt;Atomicity&lt;/strong&gt;, &lt;strong&gt;Critical Section&lt;/strong&gt;, &lt;strong&gt;Data Race&lt;/strong&gt;, &lt;strong&gt;Race Condition&lt;/strong&gt;, and the coordination paradigms for execution flows and data pipelines: &lt;strong&gt;Rendezvous&lt;/strong&gt;, &lt;strong&gt;Fork-Join&lt;/strong&gt;, and &lt;strong&gt;Fan-Out/Fan-In&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Understanding the precise definitions and differences among these concepts is crucial for designing correct concurrent systems.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="1-atomicity"&gt;1. Atomicity&lt;a class="anchor" href="#1-atomicity"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;An operation is considered &lt;strong&gt;atomic&lt;/strong&gt; if, within the context it operates, it is &lt;strong&gt;indivisible&lt;/strong&gt; and &lt;strong&gt;uninterruptible&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>Concurrency vs Parallelism</title><link>/cs/concurrency-and-parallelism/concurrency-vs-parallelism/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/cs/concurrency-and-parallelism/concurrency-vs-parallelism/</guid><description>&lt;h1 id="concurrency-vs-parallelism"&gt;Concurrency vs Parallelism&lt;a class="anchor" href="#concurrency-vs-parallelism"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Concurrency and parallelism are related but distinct concepts in computer science.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Rob Pike famously stated: &lt;strong&gt;&amp;ldquo;Concurrency is about dealing with lots of things at once. Parallelism is about doing lots of things at once.&amp;rdquo;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Katherine Cox-Buday clearly noted in &lt;em&gt;Concurrency in Go&lt;/em&gt;: &lt;strong&gt;&amp;ldquo;Concurrency is a property of the code; parallelism is a property of the running program.&amp;rdquo;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="concurrency"&gt;Concurrency&lt;a class="anchor" href="#concurrency"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Concurrency is the &lt;strong&gt;composition&lt;/strong&gt; of independently executing processes. It is a way to structure a program by breaking it into pieces that can be executed independently.&lt;/p&gt;</description></item><item><title>Multiplexer vs Dispatcher</title><link>/cs/multiplexer-vs-dispatcher/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/cs/multiplexer-vs-dispatcher/</guid><description>&lt;h1 id="multiplexer-vs-dispatcher"&gt;Multiplexer vs Dispatcher&lt;a class="anchor" href="#multiplexer-vs-dispatcher"&gt;#&lt;/a&gt;&lt;/h1&gt;

&lt;p&gt;Multiplexer (MUX) and Dispatcher are fundamental architectural concepts frequently encountered across computer science, electronics, and networking. The core distinction between them lies in the &lt;strong&gt;direction of data flow&lt;/strong&gt; and their &lt;strong&gt;primary objective&lt;/strong&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="1-basic-definitions"&gt;1. Basic Definitions&lt;a class="anchor" href="#1-basic-definitions"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th style="text-align: left"&gt;Concept&lt;/th&gt;
 &lt;th style="text-align: left"&gt;Flow Direction&lt;/th&gt;
 &lt;th style="text-align: left"&gt;Core Responsibility&lt;/th&gt;
 &lt;th style="text-align: left"&gt;Counterpart&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;strong&gt;Multiplexer (MUX)&lt;/strong&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;$N \to 1$&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Consolidates multiple input streams into a single output stream (Funneling / Merging)&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Demultiplexer (DEMUX)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;strong&gt;Dispatcher&lt;/strong&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;$1 \to N$&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Distributes incoming tasks or events from a single source to multiple destinations (Routing / Scheduling)&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Collector / Aggregator&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Multiplexer&lt;/strong&gt;: A mechanism or device that selects or merges multiple input signals/channels into a single shared output path.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dispatcher&lt;/strong&gt;: A routing controller that takes a single stream of incoming tasks, events, or requests and distributes them to suitable workers or handlers.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="2-perspectives-across-different-domains"&gt;2. Perspectives Across Different Domains&lt;a class="anchor" href="#2-perspectives-across-different-domains"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id="a-electronics--telecommunication"&gt;A. Electronics &amp;amp; Telecommunication&lt;a class="anchor" href="#a-electronics--telecommunication"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;MUX ($N \to 1$)&lt;/strong&gt;: Transmits multiple communication channels across a single physical medium (e.g. fiber, copper wire) to optimize line utilization. Examples include Time-Division Multiplexing (TDM) and Frequency-Division Multiplexing (FDM).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DEMUX ($1 \to N$)&lt;/strong&gt;: Reconstructs the aggregated transmission signal at the receiver end back into the original $N$ separate channels.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="b-concurrency-patterns"&gt;B. Concurrency Patterns&lt;a class="anchor" href="#b-concurrency-patterns"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;In the &lt;strong&gt;Fan-Out / Fan-In&lt;/strong&gt; pipeline pattern, Dispatcher and Multiplexer operate as complementary pairs.&lt;/p&gt;</description></item><item><title>Mutex vs Atomic</title><link>/cs/concurrency-and-parallelism/mutex-vs-atomic/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/cs/concurrency-and-parallelism/mutex-vs-atomic/</guid><description>&lt;h1 id="mutex-vs-atomic"&gt;Mutex vs Atomic&lt;a class="anchor" href="#mutex-vs-atomic"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;The two foundational primitives for eliminating Data Races in shared-memory concurrency are &lt;strong&gt;Mutexes&lt;/strong&gt; and &lt;strong&gt;Atomic operations&lt;/strong&gt;. They differ fundamentally in the scope of state they can protect and how they handle contention.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="1-core-comparison"&gt;1. Core Comparison&lt;a class="anchor" href="#1-core-comparison"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th style="text-align: left"&gt;Dimension&lt;/th&gt;
 &lt;th style="text-align: left"&gt;&lt;strong&gt;Mutex&lt;/strong&gt;&lt;/th&gt;
 &lt;th style="text-align: left"&gt;&lt;strong&gt;Atomic&lt;/strong&gt;&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;strong&gt;Protected Scope&lt;/strong&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;&lt;strong&gt;Multiple variables, multi-statement blocks, entire composite data structures&lt;/strong&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;&lt;strong&gt;A single scalar or pointer variable, a single operation&lt;/strong&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;strong&gt;Contention Behavior&lt;/strong&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;OS kernel or runtime scheduler &lt;strong&gt;blocks&lt;/strong&gt; the contending thread and performs a Context Switch&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Never sleeps; completes directly via &lt;strong&gt;a single CPU hardware instruction&lt;/strong&gt; (eg. &lt;code&gt;LOCK XADD&lt;/code&gt;, &lt;strong&gt;Lock-free&lt;/strong&gt;)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;strong&gt;Typical Cost&lt;/strong&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Microseconds under contention (kernel transition and scheduling overhead)&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Nanoseconds (hardware cache-coherency protocol overhead)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;strong&gt;Typical Use Cases&lt;/strong&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Linked-list/map mutations, multi-field invariants&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Single counters, state flags, reference counting&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;hr&gt;
&lt;h2 id="2-shared-rule-every-access-path-must-synchronize"&gt;2. Shared Rule: Every Access Path Must Synchronize&lt;a class="anchor" href="#2-shared-rule-every-access-path-must-synchronize"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A common misconception is that only Writers modifying a variable need Mutexes or Atomic operations while Readers can read the variable plainly without synchronization.&lt;/p&gt;</description></item></channel></rss>