Unit III Exception
Unit III Exception
Ans : Semaphore is a variable is used to solve critical section problem and to achieve process
synchronization in the multi-processing environment. The two most common kinds of
semaphores are counting semaphores and binary semaphores. Counting semaphore can take
non-negative integer values and Binary semaphore can take the value 0 & 1.
Q5. What are semaphores? Explain their types with a suitable examples.
Ans: A semaphore is a data structure consisting of a counter and a queue for storing
task descriptors. Semaphores can be used to implement guards on the code that accesses
shared data structures. The two most common kinds of semaphores are counting
semaphores and binary semaphores. Counting semaphore can take non-negative integer
values and Binary semaphore can take the value 0 & 1.
Semaphores have only two operations, wait and release (originally called P and V by
Dijkstra)
Semaphores can be used to provide both competition and cooperation synchronization.
(a) Semaphores: Wait Operation
wait(aSemaphore)
if aSemaphore‘s counter > 0 then
decrement aSemaphore‘s counter
else
put the caller in aSemaphore‘s queue
attempt to transfer control to a ready task
-- if the task ready queue is empty,
-- deadlock occurs
End
• The buffer is implemented as an ADT(abstract data type) with the operations DEPOSIT
and FETCH as the only ways to access the buffer.
Advantages: Monitors have the advantage of making parallel programming easier and less
error prone than using techniques such as semaphore.
Exception Handlers are subprograms that are not invoked by explicit calls
Special situations, called exceptions:
Error conditions
Unpredictable conditions
Tracing and monitoring
Implementation
Operating system exceptions-raised directly by hardware interrupts.
Programmer defined-the translator inserts code to handle the exceptions.
Asynchronous messaging requires additional capabilities for storing and retransmitting data
for systems that may not run concurrently, and are generally handled by an intermediary level
of software (often called middleware); a common type being Message-oriented middleware
(MOM). The buffer required in asynchronous communication can cause problems when it is
full. A decision has to be made whether to block the sender or whether to discard future
messages. A blocked sender may lead to deadlock. If messages are dropped, communication is
no longer reliable.