CONCURRENCY-PPT
Page 1: Introduction
Examines the concept of concurrency and synchronization.
Page 2: Table of Contents
01 Introduction to Concurrency
02 Deadlock and Starvation
03 Concurrency Control
04 Synchronization Primitives
Page 3: Introduction to Concurrency
Definition: Execution of multiple tasks or processes simultaneously, enhancing efficiency.
Example: A web server processing multiple client requests.
Concurrency Methods:
Creating separate threads for each request.
Processing while waiting for resources (e.g., database responses).
Using asynchronous I/O to avoid blocking.
Page 4: Key Concepts in Concurrency
Processes: Independent programs running concurrently with separate memory.
Threads: Smaller units within a process sharing memory space.
Asynchronous Programming: Tasks running independently of program flow.
Synchronization: Controls access to shared resources.
Concurrency Control: Ensures reliable transaction processing.
Page 5: Importance of Concurrency
Benefits:
Improved performance.
Responsiveness in applications.
Scalability for handling increased loads.
Fault tolerance against failures.
Allows parallel problem solving.
Page 6: Synchronization Primitives
Essential mechanisms for safe resource access by multiple threads.
Key types:
Mutexes: Prevent simultaneous resource access.
Semaphores: Control limited access resources and signal between threads.
Page 7: Mutexes
Definition: A synchronization primitive for mutual exclusion.
Purpose: Ensures only one thread accesses critical sections or shared data at a time to avoid race conditions.
Page 8: How Mutexes Work
Lock Mechanism: A thread must acquire the mutex before accessing a resource.
If locked by another thread, it waits until it is unlocked.
Page 9: Preventing Race Conditions with Mutexes
Critical for ensuring that multiple threads do not modify shared variables simultaneously.
Use Case: File I/O operations require mutexes for data integrity.
Page 10: Semaphores
Definition: A synchronization primitive allowing limited simultaneous access to resources.
Typically used for resource pooling and inter-thread signaling.
Types of Semaphores:
Counting Semaphores: Manage finite identical resources.
Binary Semaphores: Similar to mutexes, allow 0 or 1, used for thread synchronization.
Page 11: How Semaphores Work
Maintain a counter for concurrent access.
Threads decrement the counter to access resources; must wait if negative.
Page 12: Resource Pool Management with Semaphores
Useful for managing limited resources (e.g., connections, file handles).
Use Case: Producer-consumer problems ensure synchronized data production and consumption.
Page 13: Mutexes vs Semaphores
Mutexes: For mutual exclusion; only one thread accesses a resource.
Semaphores: Allow multiple threads (with limits) or signal between threads.
Page 14: Deadlock and Starvation
Introduction to the issues of deadlock and resource starvation in concurrency.
Page 15: What is Deadlock?
A situation where processes wait indefinitely for resources held by each other.
Page 16: Example of Deadlock
Visual representation showing processes (P1, P2) holding resources while waiting for others.
Page 17: Conditions for Deadlock
Mutual Exclusion: Exclusive control over resources.
Hold and Wait: Processes hold resources while waiting.
No Preemption: Resources cannot be taken from processes.
Circular Wait: Each process waits for a resource held by another in a cycle.
Page 18: Approaches to Handle Deadlock
01 Deadlock Prevention
02 Deadlock Avoidance
03 Deadlock Detection and Recovery
Page 19: Deadlock Prevention Techniques
Eliminate mutual exclusion, hold and wait, no preemption, circular wait.
Page 20: Deadlock Detection and Recovery
Techniques: Resource allocation graph (RAG), wait-for graph (WFG), process termination, resource preemption, rollback.
Page 21: What is Starvation?
A low-priority process cannot acquire resources due to high-priority processes hogging them.
Page 22: Starvation Example
Visual representation of processes with varying priorities and their arrival times.
Page 23: Causes of Starvation
High-Priority Processes: Favored by schedulers.
Circular Waiting: In deadlock scenarios affecting resource availability.
Page 24: Additional Causes of Starvation
Limited access in multiprocessor systems.
Resource contention due to system overload.
Page 25: Solutions to Prevent Starvation
Aging: Increase the priority of processes waiting long.
Priority Inheritance: Temporarily boost low-priority process priority for a needed resource.
Round Robin Scheduling: Fairly allocate time slices for processes.
Page 26: Concurrency Control Mechanisms
Techniques to ensure safe and consistent concurrent transaction execution.
Page 27: Lock-based Concurrency Control
Shared Locks (S-lock): Allow multiple reads but no modifications.
Two-Phase Locking (2PL):
Growing phase (acquire locks).
Shrinking phase (release locks).
Page 28: Timestamp-based Concurrency Control
Each transaction gets a unique timestamp; conflicts resolved based on timestamps.
Optimistic Concurrency Control (OCC): Transactions execute without locks, checked at commit time for validity.
Page 29: Multiversion Concurrency Control (MVCC)
Supports multiple data versions, allowing readers access to older versions and writers to work on the latest.
Page 30: Transaction Management
Overall control of transactions to ensure isolation, consistency, and integrity in a concurrent environment.
Page 31: Key Properties of Transactions
Atomicity: Ensures success or rollback of all operations.
Consistency: Maintains valid state transitions.
Isolation: Prevents interference from concurrent transactions.
Durability: Ensures committed changes persist despite failures.
Page 32: Consistency and Isolation Levels
Concept of ensuring all transactions maintain a consistent state throughout operations.
Page 33: Consistency Levels
Ensures transitions between valid database states, diet with integrity rules.
Page 34: Isolation Levels
Prevent conflicts and anomalies between concurrent transactions.
Page 35: Examples of Consistency and Isolation Levels
Read Uncommitted: May allow dirty reads.
Read Committed: Avoids dirty reads; still allows non-repeatable reads.
Page 36: Isolation Levels Continued
Repeatable Read: Prevents non-repeatable reads; might allow phantom reads.
Serializable: Highest level; prevents all inconsistencies.
Page 37: Closing
Upcoming recitation and quiz overview.