Chapter 17

Threads and Nondeterminism

Sequential programs have a single thread of execution. Programs can be made concurrent by creating additional threads so that multiple threads execute a program in parallel. How threads access hardware computing resources is typically orchestrated by a scheduler—often in the operating system—which is not under a programmer’s control. As a result, and in the absence of additional synchronization, the exact order in which multiple threads jointly execute their instructions is unpredictable. Consequently, multithreaded programs tend to exhibit nondeterministic behavior. This nondeterminism vastly complicates testing and debugging.

17.1 Threads of Execution

A thread of execution—or thread, for short—represents ...

Get Functional and Concurrent Programming: Core Concepts and Features now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.