.. _SynchOverview: .. raw:: html .. |--| unicode:: U+2013 .. en dash .. |---| unicode:: U+2014 .. em dash, trimming surrounding whitespace :trim: .. This file is part of the OpenCSF eTextbook project. It was .. auto-generated by scripts from the OpenDSA eTextbook project. .. See https://OpenCSF.org for more details. OpenCSF is distributed .. under a Creative Commons Attribution-NonCommercial 4.0 International .. License (see http://creativecommons.org/licenses/by-nc/4.0/), .. Copyright (c) 2019-2021 by Michael S. Kirkpatrick. OpenDSA is .. distributed under an MIT open source license, Copyright (c) 2012-2021 .. by the OpenDSA Project Contributors. .. avmetadata:: :author: Michael S. Kirkpatrick :requires: :satisfies: Synchronization Introduction :topic: Synchronization Primitives Synchronization Primitives ========================== .. figure:: Images/CSF-Timeline.7.png :align: center :width: 90% :figwidth: 100% :alt: Timeline of major CSF topics with Multicore and Threads highlighted .. raw:: html
The resurgence of interest in multithreading in the late 1990s brought synchronization with it as a core topic. When multiple threads share an address space, they must ensure not to conflict in their memory accesses. Edsger Dijkstra's THE OS introduced semaphores as a software construct in 1968, while the POSIX.1c-1995 standard defined an interface for them. In addition, higher-level primitives have made synchronization more manageable as a key infrastructure component for concurrent software. .. topic:: Chapter Objectives .. figure:: Images/CSF-Images-Objectives.png :align: left :figwidth: 5% :width: 100% :alt: Decorative chapter objectives image In this chapter, we will address the following instructional objectives: * We will justify the need for synchronization primitives as solutions to race conditions and timing constraints. * We will compare and contrast primitive synchronization mechanisms and what problems they solve. * We will examine code using the POSIX thread library's synchronization primitive implementations. * We will identify the conditions that lead to deadlock, a difficult race condition that can arise in synchronized software. Concurrent programs introduce a new class of software bugs called :term:`race conditions“It’s not an idea until you write it down.”