0% found this document useful (0 votes)
4 views5 pages

ES Unit-5 Answers

The document discusses semaphores as synchronization tools in operating systems, highlighting their role in managing concurrent processes, preventing race conditions, and ensuring resource sharing. It details two types of semaphores: binary and counting, and their applications in various problems like mutual exclusion and producer-consumer scenarios. Additionally, it covers interrupt handling in RTOS, memory management strategies, and inter-process communication methods such as mailboxes, pipes, and queues.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

ES Unit-5 Answers

The document discusses semaphores as synchronization tools in operating systems, highlighting their role in managing concurrent processes, preventing race conditions, and ensuring resource sharing. It details two types of semaphores: binary and counting, and their applications in various problems like mutual exclusion and producer-consumer scenarios. Additionally, it covers interrupt handling in RTOS, memory management strategies, and inter-process communication methods such as mailboxes, pipes, and queues.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Unit – 5

Topic – Semaphore
A semaphore is a synchronization tool used in operating systems to manage
concurrent processes or threads. It helps avoid race conditions, deadlocks, and
ensures proper resource sharing.
1. Semaphore is a variable used to control access to a shared resource.
2. It is used in multi-threaded or multi-process environments.
3. Semaphores help in synchronization and mutual exclusion.
4. It prevents problems like two processes accessing the same data at the same
time.
5. There are two main types of semaphores:
Types of Semaphores
1. Binary Semaphore (Mutex-like) : Only two values: 0 (locked) and 1 (unlocked).
Used for mutual exclusion .Only one process can access the resource at a time
2. Counting Semaphore : Can take values 0 or more
ii) Used for counting the number of available resources
iii) Allows multiple processes to access multiple instances of a resource
Semaphores Work
wait() / P() → Decreases the semaphore value. If value < 0, the process waits.
signal() / V() → Increases the semaphore value. If any process is waiting, it gets
unblocked.
Applications of Semaphores
1.Mutual Exclusion : Ensures only one process accesses a critical section at a
time
E.g., Writing to a shared file.
2. Producer-Consumer Problem: Semaphore used to synchronize producer
(adding items) and consumer (removing items) in a buffer.
3. Reader-Writer Problem: Semaphore controls whether multiple readers can
read simultaneously, but only one writer can write.
4. Dining Philosophers Problem: Prevents deadlock when philosophers
(processes) try to pick up shared chopsticks (resources).
5. Thread Synchronization: Ensures threads execute in a specific order or
complete one task before another begins.
6. Operating System Scheduling: Semaphores are used in process scheduling,
interrupt handling, and resource management.

Topic - Interrupt Routines are handled by an RTOS :


Interrupt: An interrupt is a signal that tells the processor to temporarily stop
what it's doing and handle something urgent (like a button press or a sensor
reading).
RTOS Handles Interrupts :
1. Interrupt Occurs: A hardware device sends an interrupt signal to the CPU (e.g.,
timer, sensor, communication).
2. Processor Pauses Current Task: The CPU stops the current task and saves its
state (context) to resume later.
3. ISR (Interrupt Service Routine) :The RTOS runs a small function called ISR to
handle the interrupt.
4. Keep ISRs Short and Fast: RTOS recommends keeping ISRs very short to
quickly return control to the system.
5. Do Not Call RTOS APIs in ISR (Usually): Most RTOS functions (like task delay
or memory allocation) should not be used in ISRs.
6. Use Flags or Queues to Communicate with Tasks: ISRs usually set a flag or
send a message to a task to handle the main work later.
7. Context Switching May Happen After ISR: If the ISR wakes a higher-priority
task, the RTOS may switch to that task immediately after the ISR ends.
8. RTOS Restores the Paused Task: Once the ISR is done and any context
switching is complete, the RTOS resumes normal operation.
Topic - Memory management in RTOS
Memory management is how the RTOS handles RAM (memory) to store
variables, tasks, stacks, queues, etc.
Memory Management Works in RTOS -
1. Static vs Dynamic Allocation
Static: Memory is fixed at compile time. Safe and predictable.
Dynamic: Memory is allocated at runtime. Flexible but needs care.
2. Task Stack Allocation: RTOS either allocates this statically or dynamically when
creating a task.
3. Heap Management: RTOS uses a heap (a pool of memory) for dynamic
allocation. Heap is managed using different algorithms (like heap_1, heap_2 in
FreeRTOS).
4. Memory Pools (Fixed-size blocks): Some RTOSes use memory pools:
predefined blocks of memory for quick, efficient use.
ii) Faster and avoids fragmentation.
5. Avoiding Fragmentation: RTOS tries to avoid fragmentation (scattered free
memory) to keep the system stable.
6. Safe Access (No Overlaps): RTOS protects memory regions so that tasks don’t
overwrite each other's memory.
7. Failure Handling: If memory runs out, the RTOS handles it gracefully (e.g.,
return NULL, error flags).
8. Special Regions for ISR, Kernel, and Tasks: RTOS may divide memory: one part
for kernel, one for ISRs, and others for tasks.

Topic
(i) Mailbox and Message for Inter-Process Communication (IPC)
* Mailbox:
* Think of a mailbox as a designated place.
* Processes can send messages to a mailbox.
* Other processes can read messages from that mailbox.
* Message:
* The actual data or information being sent.
* Can be simple (like a number) or complex (like a structured data).
* Messages are "posted" to a mailbox.
* How it works:
1. A process prepares a message.
2. It sends the message to a specific mailbox.
3. Another process reads the message from that mailbox.
4. The message is then processed.
(ii) Pipe and Queue for Multitasking
* Pipe:
* A one-way communication channel.
* Data flows in a specific direction (like a pipe).
* One process writes data into the pipe.
* Another process reads data from the pipe.
* Queue:
* A data structure where items are added at one end and removed from the
other (FIFO - First In, First Out).
* Processes can add messages to the queue.
* Other processes can read messages from the queue.
* Queues can handle multiple senders and receivers.
* How it works:
1. A process puts data into a pipe or queue.
2. Another process retrieves data from the pipe or queue.
3. The data is then processed by the receiving process.
(iii) Semaphores:
* A synchronization mechanism.
* Used to control access to shared resources.
* Can be thought of as a "lock" or a "counter".
* Two main operations:
* Wait (or P or acquire): Decrements the semaphore value. If the value is
negative, the process blocks.
* Signal (or V or release): Increments the semaphore value. If any processes
are blocked, one is released.
* Used to prevent race conditions and ensure data integrity.
* (ii) Mailbox: (See the explanation above).
* (iii) Pipes: (See the explanation above).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy