This is my scenario.
I have a pool of frequencies and my BaseStation
needs to select one of them. The critical section for a BaseStation
is the phase when it goes into frequency selection. Once it selects frequencies, control returns back to the main BaseStation
class and it resumes its request generation. At the same time, i.e. as soon as it exits its critical section, the frequency that was selected will go into a use state for a certain period of time, that will be decided by the random clock. So this frequency will be unavailable for any other request that happens in the interim. Once, the frequency use time is over, it just sets its status as available again. So the mutual exclusion part for the BaseStation
is only for frequency selection, once that's over, the BaseStation
functionality and the frequency use time run parallely.
How I've coded so far is: I have three classes BaseStation
, CriticalSection
and UseFrequency
. BaseStation
calls a function in CriticalSection
for frequency selection, once the frequency is selected I have a function that starts a thread in another class for frequency use and then returns control to BaseStation
soon after:
UseFrequency freqInUse = new UseFrequency;
freqInUse.start();
return 1;
But once the thread stops, the class CriticalSection
needs some variables updated, I'm confused how to return control back to the middle class. Would I need to use two threads?