Shared mutable state
Shared mutable state is data or computational state that multiple components or execution contexts can access and modify.
Functional Design and Architecture: Examples in Haskell
Shared mutable state is changeable data that can be accessed and modified by multiple concurrent computations.
- How it is used
- Uses mutable shared state to motivate functional restrictions and illustrate communication hazards between concurrent threads.
- How deep it goes
- Explains concurrency risks and demonstrates an unsafe read-and-write design, without developing a thread-safe replacement.
- Examples
- Uses astronomer and tracking-center threads sharing a meteor-reporting list to illustrate lost or duplicated reports.
- What you can do after
- Evaluate shared-state designs for opportunities for concurrent interference and understand why immutability can avoid a class of parallel bugs.
Read how Functional Design and Architecture: Examples in Haskell explains shared mutable state →
Functional Programming in C#, Second Edition
Shared mutable state is changeable program state accessible to multiple parts of a program or concurrent computations.
- How it is used
- Motivates synchronization in multithreaded applications while contrasting independently computed results in parallel processing.
- How deep it goes
- Explains lost updates and temporary invariant violations, then summarizes synchronization and message-passing alternatives.
- Examples
- Uses product inventory updates, a low-inventory flag, account-number generation, and server-side caching as examples.
- What you can do after
- Evaluate shared mutable state risks and compare synchronization with exclusive ownership through message passing.
Read how Functional Programming in C#, Second Edition explains shared mutable state →
The Art of Unit Testing 3e
Mutable data or external state that is accessible by multiple tests or software components.
- How it is used
- Identifies dependencies between tests that can make results change with test order or parallel execution.
- How deep it goes
- Explains order-dependent corruption and flaky runs, then illustrates per-test setup while leaving a complete correction for later.
- Examples
- Uses an external database or service and a Jest suite with a shared verifier and an unreset errors array.
- What you can do after
- Diagnose/debug with it by checking test-order effects, unreset data, and mutable variables shared across tests.
Read how The Art of Unit Testing 3e explains shared mutable state →
F# in Action: A Revised Edition of Get Programming with F#
Shared mutable state is changeable program state that can be accessed by multiple parts of an application or by concurrent computations.
- How it is used
- Identifies a cause of hard-to-reproduce application bugs and synchronization difficulties in concurrent work.
- How deep it goes
- Works through debugging and threading failures, then gives practical alternatives without a cache implementation.
- Examples
- Uses a Visual Studio debugging session, a Parallel.ForEach race, an asynchronous customer reference, and a customer cache.
- What you can do after
- Diagnose/debug with it by examining state changes and ordering; prefer immutable pipelines or controlled access when sharing is necessary.
Read how F# in Action: A Revised Edition of Get Programming with F# explains shared mutable state →
C++ Concurrency in Action, Second Edition
Shared mutable data is information accessible by multiple threads that can also be modified during execution.
- How it is used
- Coordinates access to data shared between threads and highlights the rules needed to avoid concurrency bugs.
- How deep it goes
- Explains mutex protection, encapsulation, and pointer or reference backdoors through a shared-list example.
- Examples
- Uses an apartment-sharing analogy and a shared std::list<int> protected during list operations.
- What you can do after
- Apply std::mutex and std::lock_guard to guard shared-list operations, while designing interfaces that do not leak pointers or references.
Read how C++ Concurrency in Action, Second Edition explains shared mutable state →
Deep Learning with R, Third Edition
Global state is mutable information maintained outside a function and implicitly shared across calls.
- How it is used
- Explains why random-number calls differ in R and motivates explicit seed management in stateless JAX.
- How deep it goes
- Traces R’s hidden seed state, demonstrates explicit seeds and JAX keys, but omits the mechanics of restoring R’s original seed.
- Examples
- Uses repeated runif() calls, a seeded R noise function, and repeated or split JAX PRNG keys.
- What you can do after
- Apply explicit R seeds or JAX PRNG keys to make random-number generation repeatable, splitting keys when new values are needed.
Read how Deep Learning with R, Third Edition explains shared mutable state →
Web Component Development with Modern Libraries and Tooling
The coordination of one data state across multiple components so their representations remain synchronized.
- How it is used
- Keeps multiple web-component displays synchronized when their underlying data changes.
- How deep it goes
- Works through an ancestor-and-events approach and a FAST state-object example, without detailing the state function’s internals.
- Examples
- Uses a shopping-cart item list and totals, plus a shared name edited by an input and restored by a reset button.
- What you can do after
- Apply it via FAST’s `state` function to synchronize components, or implement ancestor-held state with properties and bubbling events.
Read how Web Component Development with Modern Libraries and Tooling explains shared mutable state →
100 Go Mistakes and How to Avoid Them
Mutable shared state is data that can be modified and is accessible by multiple parts of a program or concurrent executions.
- How it is used
- Controls time-dependent cache trimming in tests by making the current time replaceable.
- How deep it goes
- Explains how a global clock couples tests, then contrasts struct-level clock injection with caller-supplied timestamps.
- Examples
- Uses a cache that trims timestamped events, a global clock variable, and a fixed-time test dependency.
- What you can do after
- Apply clock injection or caller-supplied cutoffs to make time-dependent tests deterministic and isolated.
Read how 100 Go Mistakes and How to Avoid Them explains shared mutable state →
Also covered in
- Event Processing in Action
- Learn Concurrent Programming with Go
- Akka in Action, Second Edition
- Rust Servers, Services, and Apps
- Context EngineeringIn early access (MEAP)
- Build a Frontend Web Framework (From Scratch)
- Secrets of the JavaScript Ninja, Third EditionIn early access (MEAP)
- Advanced Algorithms and Data Structures
- Writing for Developers: Blogs that get read
- Grokking Simplicity
- Fabulous Adventures in Data Structures and Algorithms
What to know first
- threadA thread is a distinct sequence of execution with its own control flow and state, managed or scheduled by a processor, runtime, or operating system.
- multithreadingMultithreading is the execution of multiple threads of control within a program, concurrently through interleaving or simultaneously.
- Document Object ModelThe Document Object Model is a platform-independent programming interface that represents a document as a structured tree of nodes and provides ways to access and modify its content and structure.
- domain modelA domain model is a software representation of the concepts, entities, relationships, rules, and behavior of a problem domain.
Related concepts
- integration testused by · An integration test evaluates whether multiple software components, or a component and an external dependency, interact and behave correctly together.
- enrich agentused by · An enrich agent is a translate agent that adds information to an event using data obtained from a global state element.
- threadused by · A thread is a distinct sequence of execution with its own control flow and state, managed or scheduled by a processor, runtime, or operating system.
- statekind of · State is information describing the condition or configuration of a system or computation at a particular time that may influence its behavior or subsequent transitions.
- actorused by · An actor is a person, system, process, or computational entity that performs actions or participates in interactions within a system.
Questions about shared mutable state
What is shared mutable state?
Shared mutable state is data or computational state that multiple components or execution contexts can access and modify.
Which Manning books explain shared mutable state?
Functional Design and Architecture: Examples in Haskell, Functional Programming in C#, Second Edition, The Art of Unit Testing 3e, F# in Action: A Revised Edition of Get Programming with F#, C++ Concurrency in Action, Second Edition, Deep Learning with R, Third Edition, Web Component Development with Modern Libraries and Tooling and 100 Go Mistakes and How to Avoid Them.
What should I know before learning shared mutable state?
Manning books that teach shared mutable state usually introduce thread, multithreading, Document Object Model and domain model first.
What is the difference between shared mutable state and local state?
Shared mutable state is data or computational state that multiple components or execution contexts can access and modify. Local state is information maintained within a particular computation or agent for its own processing rather than shared throughout a broader system.
What is shared mutable state a kind of?
Shared mutable state is a kind of state. State is information describing the condition or configuration of a system or computation at a particular time that may influence its behavior or subsequent transitions.
What is shared mutable state also called?
Shared mutable state is also called shared state or global mutable state.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.







