Changes
→Implementation
==Communicator==
===Implementation===
We add new state variables (a lock, a bool, two four counters, and two condition variables):Lock lockint speakerCountactiveSpeakersint listenerCountwaitingSpeakersbool exInProgressint activeListenersint waitingListenersCondition speakersCondition listeners.* We use a Boolean flag which indicates if a transfer is in progress.Condition return* A The first lone first speaker or listener will be counted as active, or in the process of exchanging a message and returning, and will sleep on its respective the return condition variable until its counterpart wakes it up so that they can both return.* A second thread performing the same action as a counterpart action to the first currently active thread will set the exInProgress flag to truebe counted as waiting, perform its actions and wake the 1st thread; any intruding 3rd thread will not attempt be put to proceed as long as the exInProgress flag is trueвАФthis 3rd thread will sleep on its respective condition variable. Otherwise, so that we can maintain synchronicity.* The 1st thread it will be woken up by the 2nd check if there is an active thread before of its counterpart action waiting on the 2nd thread returnsreturn condition variable. If there isn’t, at which point it will attempt to wake waiting threads of its counterpart action prior to going to sleep on the first return condition variable. If there is a counterpart active thread , it will wake it up and they both will set the Boolean return. Prior to falsereturning, a counterpart action will also attempt to wake sleeping waiting threads of its type (this is due to the possibility of additional sleeping .* Any interjecting threads being added that execute in between an exchange of message will be stopped by the moment between one thread returning and another about to return)active counters, and finally returnwhich do not decrement until BOTH counterparts in the exchange have returned.
===Testing===