Definitions & Scenarios
Acknowledgements This tutorial is based in part on Concurrency: State Models & Java Programming by Jeff Magee and Jeff Kramer.
Acknowledgements Tutorial Authors/Creators: Zhen Li, Eileen Kraemer, Zhe Zhao Computer Science Department The University of Georgia
Concurrent Program Process & Thread Thread Life Cycle
Sequential v. Concurrent Programs consist of subprograms or procedures simpler sets of activities that together make up the overall program Sequential program Subprograms are executed one after the other in fixed order, determined by program’s input Concurrent program The execution of subprograms may overlap in time
Computational activities that overlap in time may occur in parallel, or be interleaved. Concurrent Program Parallelism Interleaved
In a concurrent program, computational activities are permitted to overlap in time. Concurrent Program Parallelism Interleaved
In a concurrent program, computational activities are permitted to overlap in time. Concurrent Program Parallelism Interleaved
Process The execution of a sequential program or subprogram A unit of sequential execution A concurrent program consists of multiple processes.
Process Parallelism Interleaved Three processes in each figure
Thread A method of implementing concurrency Parallelism Interleaved Two different implementations
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield suspend resume alive
Thread Life Cycle created terminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield resume alive suspend
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield resume alive suspend
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield resume alive suspend
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield resume alive suspend
Thread Life Cycle created terminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield resume alive suspend
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield resume alive suspend
Thread Life Cycle created terminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield resume alive suspend
Thread Life Cycle created terminated Ready (Runnable) running Waiting (Non-runnable) stop dispatch yield resume alive suspend
Thread Life Cycle created terminated Ready (Runnable) running Waiting (Non-runnable) stop dispatch yield resume alive suspend
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield resume alive suspend
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop yield resume alive suspend
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop yield resume alive suspend
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield resume alive suspend
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch resume alive suspend
Thread Life Cycle createdterminated Ready (Runnable) Waiting (Non-runnable) stop startstop dispatch resume alive suspend running
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield resume alive suspend
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield resume alive
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield resume alive
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield resume alive suspend
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield alive suspend
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield alive suspend
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield resume alive suspend
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield resume alive suspend
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield resume alive
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield resume alive
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield resume alive suspend
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop start dispatch yield resume alive suspend
Thread Life Cycle created terminated Ready (Runnable) running Waiting (Non-runnable) stop start dispatch yield resume alive suspend
Thread Life Cycle created terminated Ready (Runnable) running Waiting (Non-runnable) stop dispatch yield resume alive suspend
Thread Life Cycle created terminated Ready (Runnable) running Waiting (Non-runnable) stop dispatch yield resume alive suspend
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop dispatch yield resume alive suspend
Thread Life Cycle createdterminated Ready (Runnable) running Waiting (Non-runnable) stop startstop dispatch yield resume alive suspend
Shared Objects Conditional Synchronization Resource Allocation
Shared Object Multiple threads have computational activities on the same object Ornamental Garden Garden East Turnstile West Turnstile
A Naïve Implementation Garden East Turnstile West Turnstile population thread shared object
A Naïve Implementation
Problem
Race Condition A common flaw in implementing a concurrent program with shared objects Final results depend on the execution sequence of threads Therac-25 accident
Mutual Exclusion Access to shared objects should be mutually exclusive in time
Solution Lock for atomic operation
Solution Lock for atomic operation
Review Definitions Concurrency Process & Thread Thread Life Cycle Scenarios Shared Objects – Race Conditions