---
title: "Threads and Shared Memory"
description: "Threads in one process share its address space and resources. Each has its own execution state and normally its own stack, but those stacks are not separate protected address spaces. Threads can overl"
canonical: https://lightmysky.com/learn/computing/threads-and-shared-memory-mt_N4EGNbN6Xh
source: https://lightmysky.com/learn/computing/threads-and-shared-memory-mt_N4EGNbN6Xh.md
retrieved: 2026-11-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Threads and Shared Memory

Threads in one process share its address space and resources. Each has its own execution state and normally its own stack, but those stacks are not separate protected address spaces. Threads can overlap work and waiting; conflicting accesses to shared data need coordination.

Subject: Computing · Area: Computer Systems · Ages 20 to 21
Page: https://lightmysky.com/learn/computing/threads-and-shared-memory-mt_N4EGNbN6Xh

## Ready when they can

- Say what threads in one process share and what each keeps to itself
- Explain why creating a thread usually needs less address-space setup than creating a process
- Identify a variable in a small program that two threads could reach at once

## Lesson: Threads share one memory, for better and worse

A process normally has its own virtual address space. Threads within that process share it, including program code, global variables and heap data. They also share process resources such as open files, which are not themselves memory addresses. Threads do not gain separate memory protection from each other.

Each thread has its own execution state: program counter, registers and stack pointer. It normally uses its own stack for local calls and variables. These stacks still lie in the shared address space; a pointer can let another thread reach a stack variable. In an example where A uses local a, B uses local b, and both update global total, total is the explicitly shared variable.

Creating a thread usually needs less address-space setup because it reuses its process's mappings. It still needs execution state and normally a stack. Creating a process establishes a separate address space, though techniques such as copy-on-write can avoid copying all memory immediately. Actual costs depend on the OS and workload.

With OS-scheduled threads, one thread can wait for disk input while another runnable thread computes, even on one CPU. Multiple CPUs may also run threads in parallel. During that wait, progress requires another thread that is runnable and able to proceed. The next trace shows why shared updates also need coordination.

*(drawing: In this non-atomic trace, both updates use the old value. The second store replaces the first with the same result.)*

Switching between threads of one process keeps the same process memory mappings. Each thread's execution state still has to be saved and restored. Switching to a different process may also require changing the active address-space context. Cache effects and OS details still affect the cost; a thread switch is not free.

Conflicting accesses to shared data need coordination. It is not enough to coordinate only writers if readers need a consistent result. For a shared pair that must match, coordinate reading the pair with changing it, so a reader cannot observe only half an update. Sharing memory by itself provides no such rule.

**Recap.** Threads share process memory and resources but keep separate execution state. Shared data needs coordinated access; lower setup cost and progress depend on context.

*Original lesson, questions and flashcards about thread execution state and shared memory.*

## Practice

8 questions on this page, each with its working shown.

## Needs first

- [Virtual Memory and Address Translation](https://lightmysky.com/learn/computing/virtual-memory-and-address-translation-mt_B-PiAyderj)

## Opens up

- [Race Conditions and Mutual Exclusion](https://lightmysky.com/learn/computing/race-conditions-and-mutual-exclusion-mt_hygT74jJDE)
