0% found this document useful (0 votes)
13 views14 pages

Apex Institute of Technology: Department of Computer Science & Engineering

The document provides an overview of semaphores, spinlocks, and blocking semaphores in the context of operating systems, detailing their definitions, performance characteristics, advantages, and disadvantages. It compares busy-waiting (spinlock) and blocking (sleep-wait) semaphores in terms of CPU utilization, overhead, performance, resource usage, complexity, scalability, and kernel involvement. The course outcomes and unit syllabus related to operating systems are also outlined, emphasizing the importance of process management and synchronization techniques.

Uploaded by

trivangi70
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views14 pages

Apex Institute of Technology: Department of Computer Science & Engineering

The document provides an overview of semaphores, spinlocks, and blocking semaphores in the context of operating systems, detailing their definitions, performance characteristics, advantages, and disadvantages. It compares busy-waiting (spinlock) and blocking (sleep-wait) semaphores in terms of CPU utilization, overhead, performance, resource usage, complexity, scalability, and kernel involvement. The course outcomes and unit syllabus related to operating systems are also outlined, emphasizing the importance of process management and synchronization techniques.

Uploaded by

trivangi70
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

APEX INSTITUTE OF

TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE &
ENGINEERING

OPERATING SYSTEM
Faculty: Ms. Anudeep Kaur(E16380)

Lecture 4 DISCOVER . LEARN .


EMPOWER 1
Table of Contents
Semaphore - Overview
Spinlock (Busy-waiting)
Blocking (Sleep-Wait)
Comparison
COURSE OUTCOME
CO1 Remember and understand fundamental functions of operating system.

CO2 Understand Process and Disk scheduling algorithms and apply the best scheduling
algorithm for a given problem instance.

CO3 Apply an algorithm for process scheduling, deadlock avoidance and file management.

CO4 Identify and analyze memory management techniques and apply them for memory
management related problems.

CO5 Analyze the performance of process management, resource management and


deadlock management techniques and apply the best methods for a given problem
instance.
UNIT-1 SYLLABUS
Unit-1 Contact Hours: 15 HOURS

Operating System Introduction to Operating Systems, Operating System Structure, Main Functions and
characteristics of Operating Systems, Types of Operating Systems, System calls, Types
Overview of system calls, System programs, Reentrant Kernels, Monolithic and Microkernel
Systems

Process Process Concept, Process Control Block, Process Scheduling, Threads, CPU Scheduling:
Preemptive/Non-Preemptive Scheduling, Scheduling Criteria, Scheduling Algorithms
Management (FCFS, SJF, RR), Priority, real-time scheduling.

Semaphores Inter Process Communication, Semaphores, Atomic Transactions, Semaphore


Implementation-1, Semaphore Implementation-2
Semaphore - Overview
The semaphore is basically a technique used to manage concurrent processes by using a simple integer value
that is used to control the access on multiple processes and to avoid critical section problem in the system
such as multitasking in operating system. It’s a variable that is non-negative and shared between threads. It
includes waiting list of process, counter and also supports two different type of atomic operations i.e. wait
and signal for process synchronization. It is categorized into binary and counting semaphore.
1.Binary semaphore – Binary semaphore have only two value 0 and 1. It handles or remove the problem of
critical section with multiple processes. Binary semaphore is also known as mutex lock.
2.Counting semaphore – It is helpful to control the access to a resource which include multiple instances.
These values have an unrestricted value domain. It counts the number of available resource.
Spinlock (Busy-waiting)

Definition: A spinlock is a type of busy-waiting semaphore where a thread repeatedly checks if the lock is
available in a tight loop. The thread "spins" until the lock becomes available.

The spinlock is a locking system mechanism. It allows a thread to acquire it to simply wait in loop until the lock
is available i.e. a thread waits in a loop or spin until the lock is available. Spinlock is held for a short period of
time. Spinlock are useful in multiprocessor system.
We use Spinlocks When:
•The critical section is very short.
•Lock contention is expected to be low.
•The overhead of context switching is greater than the cost of busy-waiting.
•You are in a real-time system where response time is critical.
Spinlock (Busy-waiting)
Performance:
•Low Overhead: Spinlocks have low overhead in terms of context switches because the thread does not relinquish the CPU
while waiting.
•Short Wait Times: Spinlocks are efficient when the expected wait time is short, as they avoid the overhead of putting a
thread to sleep and waking it up.
•CPU Utilization: Spinlocks can be wasteful in terms of CPU utilization. While waiting, the thread consumes CPU cycles
without doing useful work.

System Resource Usage:


•CPU Consumption: Busy-waiting consumes CPU cycles, which can lead to reduced performance for other processes and
overall system inefficiency.
•Cache Effects: Spinlocks can benefit from being cache-friendly if the critical section is short and the lock acquisition is quick,
reducing memory access latency.
Advantages and Disadvantages Spinlock (Busy-waiting)
Advantages:
•Low Overhead: Minimal context switching overhead.
•Simplicity: Easy to implement and understand.
•Fast for Short Waits: Ideal for very short critical sections where the lock is held for a brief period.

Disadvantages:
•High CPU Usage: Can waste CPU cycles on busy-waiting, especially if the lock is held for long periods.
•Poor Scalability: Not suitable for high contention scenarios or longer critical sections.
•Resource Contention: Can lead to performance degradation if many threads are spinning.

Suitable Scenarios
Spinlocks are most suitable in scenarios where:
•Short Critical Sections: The code within the critical section executes very quickly.
•Low Contention: There is minimal contention for the lock.
•Real-Time Requirements: Response time is critical, and the overhead of blocking and context switching must be minimized.
Blocking (Sleep-Wait)
Blocking (Sleep-Wait) Semaphore
A blocking semaphore, also known as a sleep-wait semaphore, is a synchronization primitive used to manage
concurrent access to shared resources by putting threads to sleep when they cannot immediately proceed. This
approach is efficient for scenarios with longer wait times and higher contention, as it frees up the CPU to
perform other tasks rather than wasting cycles on busy-waiting.

We use Blocking Semaphores When:


•The critical section is long.
•High lock contention is expected.
•CPU efficiency is important.
•You are in a general-purpose operating system where multiple processes need to share CPU time efficiently.
Blocking (Sleep-Wait)
Performance:
•High Overhead: Blocking incurs higher overhead due to context switches, as putting a thread to sleep and
waking it up involves significant kernel operations.
•Long Wait Times: Blocking is more efficient for longer wait times because it frees the CPU to perform other
tasks while the thread is waiting.
•Reduced CPU Utilization: Blocking is generally more CPU-efficient, as the CPU is not wasted on busy-waiting.
System Resource Usage:
•Memory Usage: Blocking requires additional memory for managing wait queues and maintaining the state of
sleeping threads.
•Kernel Involvement: Blocking relies more on the operating system’s scheduler and kernel mechanisms to
manage sleeping and waking threads, increasing the complexity of the implementation.
Advantages and Disadvantages
Advantages:
•CPU Efficiency: Does not waste CPU cycles on busy-waiting, allowing better overall system performance and efficiency.
•Scalability: More scalable in high contention scenarios, as threads are put to sleep rather than consuming CPU resources.
•Fairness: Generally provides fairer access to resources as threads are woken up in the order they were put to sleep.

Disadvantages:
•Higher Overhead: The cost of context switching and maintaining wait queues can be significant.
•Complexity: More complex to implement and manage due to kernel-level interactions.

Suitable Scenarios
Blocking (sleep-wait) semaphores are most suitable in scenarios where:
•High Contention: Multiple threads frequently compete for the same resource.
•Long Wait Times: Threads may need to wait for significant periods before accessing the resource.
•Resource Efficiency: Efficient use of CPU and other system resources is critical.
Comparison
Aspect Busy-Waiting (Spinlock) Blocking (Sleep-Wait)

CPU Utilization High (wastes CPU cycles) Low (frees CPU for other tasks)

Overhead Low (no context switches) High (context switches required)


Performance Efficient for short wait times Efficient for long wait times
Resource Usage Consumes CPU cycles Requires memory for wait queues
Complexity Simple to implement More complex due to kernel involvement

Scalability May lead to contention and performance issues Scales better by allowing other processes to run

Cache Effects Cache-friendly for short critical sections Less dependent on cache

Kernel Involvement Minimal Significant


E-Video Links
https://www.youtube.com/watch?v=bkSWJJZNgf8&list=PLxCzCOWd
7aiGz9donHRrE9I3Mwn6XdP8p
• https://www.youtube.com/watch?v=vBURTt97EkA&list=PLBlnK6fE
yqRiVhbXDGLXDk_OQAeuVcp2O
• https://nptel.ac.in/courses/106/108/106108101/
.

You might also like