Explain the synchronization imposed by the following Ada protected object:
protected type Barrier(Needed : Positive) is
entry Wait;
private
Releasing : Boolean := False;
end Barrier;
protected body Barrier is
entry Wait when Wait'Count = Needed or Releasing is
begin
if Wait'count $=0$ then
Releasing = False;
else
Releasing := True;
end if;
end Wait;
end Barrier;
The following package provides a simplified Ada binding to Real-Time POSIX Mutexes and Condition Variables. All Mutexes and Condition Variables are initialized with default attributes.
package Pthreads is
type Mutex_T is limited private;
type cond_T is limited private;
procedure Mutex_Initialize (M: in out Mutex_T);
procedure Mutex_Lock(M: in out Mutex_T);
procedure Mutex_Trylock (M: in out Mutex_T);
procedure Mutex_Unlock(M: in out Mutex_T);
procedure Cond_Initialize(C: in out Cond_T);
procedure Cond_Wait (C: in out Cond_. $T$;
$\mathrm{M}$ : in out Mutex_T);
procedure Cond_Signal (C: in out Cond_T);
procedure Cond_Broadcast (C: in out Cond_T);
private
. . .
end Pthreadis;
Show how Barriers, as defined above, can be implemented using this package. Do not use any of Ada's communication and synchronization facilities in the solution.