Notes - MIECT
Sistemas De Operação
Notes - MIECT
Sistemas De Operação
  • Sistemas de Operação
  • Processes in Unix/Linux
    • Process
    • Multiprocessing vs. Multiprogramming
    • Processes in Unix
    • Execution of a C/C++ program
  • Introduction to operating systems
    • Global view
    • Evolution of computational systems
    • Key topics
  • Semaphores and Shared memory
    • Concepts
    • Semaphores
    • Shared memory
    • Unix IPC primitives
  • Threads, mutexes and condition variables in Unix/Linux
    • Threads
      • In linux
    • Monitors
    • Unix IPC primitives
  • Processes
    • Process
      • Diagrams
    • Process control table
    • Context switching
    • Threads
  • Processor Scheduling
    • Processor Scheduler
    • Short-term processor scheduler
    • Scheduling algorithms
    • Scheduling criteria
    • Priorities
    • Scheduling policies
      • In Linux
  • Interprocess communication
    • Concepts
    • Philosopher dinner
    • Access primitives
      • Software solutions
      • Hardware solutions
    • Semaphores
    • Monitors
    • Message-passing
    • Unix IPC primitives
  • Deadlock
    • Introduction
    • Philosopher dinner - Solution 1
      • Deadlock prevention
    • Philosopher dinner - Solution 2
      • Deadlock prevention
    • Philosopher dinner - Solution 3
      • Deadlock prevention
    • Philosopher dinner - Solution 4
    • Deadlock avoidance
    • Deadlock detection
  • Memory management
    • Introduction
    • Address space
    • Contiguous memory allocation
    • Memory partitioning
    • Virtual memory system
    • Paging
    • Segmentation
    • Combining segmentation and paging
    • Page replacement
      • Policies
    • Working set
    • Thrashing
    • Demand paging vs. preparing
Powered by GitBook
On this page
  • Definition
  • An implementation of semaphores
  • Bounded-buffer problem
  • Analysis of semaphores
  1. Interprocess communication

Semaphores

PreviousHardware solutionsNextMonitors

Last updated 2 years ago

Definition

A semaphore is a synchronization mechanism, defined by a data type plus two atomic operations, down and up.

Data type:

Operations:

  • down

    • block process if val is zero.

    • decrement val otherwise.

  • up

    • if queue is not empty, wake up one waiting process (accordingly to a given policy).

    • increment val otherwise.

Note that val can only be manipulated through these operations.

  • It is not possible to check the value of val.

An implementation of semaphores

Internally, the block_on_sem function must enable interruptions.

This implementation is typical of uniprocessor systems. Why?

Semaphores can be binary or not binary.

How to implement mutual exclusion using semaphores?

  • Using a binary semaphore.

Bounded-buffer problem

How to implement using semaphores?

  • guaranteeing mutual exclusion and absence of busy waiting.

fifo.notEmpty()and fifo.notFull() are no longer necessary. Why?

One can easily make a mistake.

What is wrong with this solution? It can cause deadlock.

Analysis of semaphores

Concurrent solutions based on semaphores have advantages and disadvantages.

Advantages:

  • Support at the operating system level – operations on semaphores are implemented by the kernel and made available to programmers as system calls.

  • General – they are low level contructions and so they are versatile, being able to be used in any type of solution.

Disadvantages:

  • Specialized knowledge – the programmer must be aware of concurrent programming principles, as race conditions or deadlock can be easily introduced.

This solution can suffer race conditions.
Mutual exclusion is guaranteed, but suffers from busy waiting