Urgent.News

What's breaking now, across thousands of outlets.

Tech

Concurrency Programming (0): The Problem Space and Scope

Table of Contents 1. Define the Scope First 2. Start with a Shared Variable 3. Two Main Coordination Models 3.1 Shared Memory: Protect Shared State with Synchronization 3.2 Message Passing: Coordinate through Messages 4. Why Does This Code Work Correctly? 5. Languages Need to Define Concurrency Semantics 6. Why Do We Still Need to Go Down to the Hardware? 7. Next: Start with the Hardware 1.…

1. This article series focuses on concurrency within a single process on a single machine, specifically multiple execution units inside the same process. Examples include Java threads, Go goroutines, and Python threads or asyncio tasks. Inter-process communication, distributed systems, and network communication are not covered.

2. To understand concurrency, start with a shared variable. Consider a process containing this variable: count = 0. Two execution units, Thread A and Thread B, both attempt to increment count twice. The final result is not guaranteed to be count = 2 due to how count++ can be broken down into three steps: read count, compute count + 1, and write count back.

3. Two main coordination models for concurrent programming are shared memory and message passing. Shared memory involves multiple execution units directly accessing the same state, while message passing involves execution units exchanging information through messages. Both models aim to handle the problem of modifying shared state concurrently.

4. The code works correctly in both synchronization and message passing approaches because of certain fundamental principles: atomicity, visibility, and ordering. These principles ensure that operations are executed as single, uninterruptible steps (atomicity), changes are immediately visible to other execution units (visibility), and operations occur in a specific sequence (ordering). These rules are defined by the programming language's concurrency semantics.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Why I'll Never Watch GOTHAM

The television show Gotham was inspired by Gotham Central, one of the best Batman comic series out there. So what's preventing Susana from simply enjoying it for what it is?

More from Tuesday 15 September →