ch5 - IPC

Interprocess Communication (IPC)

  • IPC is crucial in multi-threaded environments to enable communication between processes.

Outline

  • Interprocess Communication (IPC)

  • Mutual exclusion

  • Synchronization

  • Deadlock

  • Solution approaches to IPC problems

    • Software-based solutions

    • Hardware-based solutions

    • Both types of solutions

  • Semaphore structure

  • Monitor structure

Objectives

  • Illustrate and describe:

    • Race conditions

    • Critical-section problems

    • Synchronization issues

    • Deadlock situations

  • Illustrate hardware solutions for critical-section problems using test-and-set, compare-and-swap operations.

  • Demonstrate software solutions using semaphores and monitors.

Introduction

  • In multi-processed environments, processes need to:

    • Communicate with one another

    • Exchange data

    • Synchronize their activities

    • Coordinate execution.

  • IPC provides methods and protocols for this communication.

Interaction Levels

  • Three levels of interaction between processes:

    • Unaware Processes (Competition)

    • Resource Management (Operating system manages)

    • Collaborative Interaction (Resource sharing and synchronization)

    • Direct Interaction (Communication between processes)

Resource Sharing Problems

  • Shared resources can lead to two main situations:

    • Mutual Exclusion:

      • Resources can either be available for shared usage or not.

    • Synchronization:

      • A process waits for another to complete before continuing.

Examples of Resource Conflict

Changing Room Scenario

  • Two boys access a changing room;

    • Boy A occupies the room, blocking Boy B.

Observer-Reporter Example

  • Two processes access a shared counter variable:

    • Race incidents may cause inaccurate counts if improperly synchronized.

Race Conditions

  • Occurs when multiple processes access shared data and result depends on execution order:

    • Example: Concurrent deposit and withdrawal on a bank account.

Critical Section (CS) and Mutual Exclusion

  • Critical Section: Code section where shared resources or data are modified.

  • Mutual Exclusion Definition: Only one process can execute CS code at a time.

  • If one process writes, no other can access the same data simultaneously.

Deadlock

  • A deadlock condition arises when processes block each other for resource access:

    • Example scenario with three processes and three resources.

Semaphores

  • Semaphores manage process access to shared resources; essential for synchronizing processes without busy waiting.

    • Operations: wait() and signal().

    • Initial value for mutual exclusion: 1; for synchronization: 0.

Hardware-Based Solutions

  • Utilize machine-level commands to manage critical section access

    • Test and Set: Atomically check and set busy states.

    • Compare and Swap: Ensures safe access to critical sections.

Monitor Structures

  • Monitors serve as higher-level abstractions for managing concurrency, ensuring only one process executes critical section code at a time.

Condition Variables

  • Used within monitors to handle execution waiting:

    • Operations: wait() suspends process, signal() resumes.

Example Monitor Structure

  • A monitor named ResourceAllocator manages a resource with methods to acquire and release access while preventing improper access sequences.