04 Quiz Arg

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

1.

In your perspective, what makes counting semaphore primitives a good concurrency


mechanism?

- As a fine-grained method of managing concurrency, semaphores have the


potential to deliver excellent performance but are challenging to utilize. Race
conditions are difficult to identify, and the mutual exclusion necessary to
eradicate them can result in deadlocks or exhaustion.

2. How does the structure of counting semaphore primitives differ from binary semaphore
primitives?

- Actually, regardless of whether the object attempting to access is a process or even a


thread, both types are utilized to synchronize access to a shared resource.
The variations are as follows:

Binary semaphores are only capable of holding two values: one to indicate that a
process or thread is in the critical section (the code that accesses the shared resource)
and that other processes or threads should wait, and the other to indicate that the
critical section is free.
Contrarily, counting semaphores accept more than two values and can take any value.
As long as they take the maximum value X, X processes or threads can use the shared
resource at once.

3. Briefly explain the purpose of the semWaitB and semSignalB function in Figure - -

- My examination of Figure 2 indicates that the semWaitB and semSignalB


functions' goal is to set the value of processes to 0 or 1. The procedure will stop
if semWaitB's value is set to 0. The procedure is repeated if it is set to 1. The
operation will not advance and will be blocked, for instance, if the value is 0. The
procedure can proceed if the process value is 1, though. If semSignalB is empty,
set the semaphore to 1 while in semSignalB. A waiting process might also be
added to the readylist as an alternative. For instance, in order to continue, the
process must be set to 1 if the queue is empty.

4. Based on Figure 1 and 2, which semaphore structure is easier to implement and why?

- The most straightforward semaphore structure to build is the counting


semaphore. The concept of counting semaphore is straightforward. since it just
uses the fundamental increment and decrement operations, unlike binary
semaphore, which uses the binary operation and can occasionally cause
confusion among other programmers. Additionally, the increment and
decrement methods clearly define what they represent. When it increases, it
means it is unblocked; when it decreases, that means it is blocked. The counting
semaphore is simpler to create than the binary semaphore, making it easier for
programmers to do so.

5. Deduce at least one characteristic of a monitor based on Figure 3. Elaborate your


answer.

- In computer languages, mutual exclusion between processes is established using


the monitor function, hence the answer is yes. The internal variables of the
monitor are not accessible by external processes, although they can invoke its
operations. Additionally, only one process may run code inside of monitors at
once. Compared to semaphore-based solutions, parallel programming using
monitors is simpler and less error-prone.

6. Would you agree that a monitor, as a concurrency mechanism, can support process
synchronization? Why or why not?

- One of the features of a monitor is the queue for an entering procedure. The
process enters in a big way at this point. Without this characteristic, a process
cannot enter the monitor, and the monitor can not support concurrent
operations. The monitor will begin the procedure as soon as possible if it is
critical. If not, the monitor will see if the procedure is prepared to start. It will be
done if it is. If not, it will delay until it is prepared to be carried out.

You might also like