/* Datatype for the tW event */
typedef TWEvent {bool isRequest; byte source};
/* Datatype for the tRM event */
typedef TRMEvent{byte source};
/* Datatype for the textUpdate event */
typedef TextUpdateEvent {byte source};



 /** Global Declarations of the TextWriter0 component */ 
bool notify_0 = false; 

inline receiveTRMEvent_0(ev) {atomic{notify_0=true;}}


 /** Global Declarations of the TextResourceManager_1 component */ 
typedef Array_1{ bool row_1[2] = true};
Array_1 column_1[2];
bool C_1[2] = false; bool T_1[2] = false; bool N_1[2] = true; 


 inline TWEventAction_1(pos, req) {
   if
     :: (req==true) ->
       atomic {
         assert(N_1[pos] && !C_1[pos] && !T_1[pos]);
         N_1[pos] = false; T_1[pos] = true;
         byte ind=2;
         do
           :: (ind==0) -> break;
           :: else -> 
             ind=ind-1;
             if
               :: (pos!=ind && T_1[ind]) -> column_1[pos].row_1[ind] = false;
               :: else -> skip;
             fi;
          od;
       }
     :: else -> atomic {
       assert(C_1[pos] && !N_1[pos] && !T_1[pos]);
       C_1[pos] = false; N_1[pos] = true;
     }
   fi;
 } 


 inline receiveTWEvent_1(event) { 
  if 
    :: (event.source==2) -> TWEventAction_1(0,event.isRequest);
    :: (event.source==0) -> TWEventAction_1(1,event.isRequest);
    :: else -> assert(0); 
  fi;
 }


 /** Global Declarations of the TextWriter2 component */ 
bool notify_2 = false; 

inline receiveTRMEvent_2(ev) {atomic{notify_2=true;}}


 /** Global Declarations of the TextResource3 component */ 
bool trflag_3 = false; 

 inline receiveTextUpdateEvent_3(ev) {
  trflag_3 = !trflag_3;
  assert(trflag_3);
  trflag_3 = !trflag_3;
 }




 /** ProcType Declarations of the TextWriter0 component */ 
active proctype run_0() {
  TWEvent requestEvent,releaseEvent;
  requestEvent.source=0;
  requestEvent.isRequest = true;
  releaseEvent.source=0;
  releaseEvent.isRequest = false;
  TextUpdateEvent textEvent;
  textEvent.source=0;

  LOOP:
  receiveTWEvent_1(requestEvent);
  atomic {(notify_0==true) -> notify_0=false;}
  receiveTextUpdateEvent_3(textEvent);
  receiveTWEvent_1(releaseEvent);
  goto LOOP
} 


 /** ProcType Declarations of the TextResourceManager_1 component */ 
active proctype run_1() {
 TRMEvent event; event.source=1;
 byte twid=0;
 LOOP: atomic { 
   (!C_1[0] && !C_1[1]) -> 
    if 
      :: (T_1[0] && (N_1[1] || column_1[0].row_1[1])) -> T_1[0]=false;C_1[0]=true;column_1[1].row_1[0]=true;
      twid=3; 
      :: (T_1[1] && (N_1[0] || column_1[1].row_1[0])) -> T_1[1]=false;C_1[1]=true;column_1[0].row_1[1]=true;
      twid=1; 
      ::else -> twid=0; 
    fi;
 } 
 if 
   ::(twid==3) -> receiveTRMEvent_2(event);
   ::(twid==1) -> receiveTRMEvent_0(event);
   :: else -> skip; 
 fi; 
 goto LOOP 
}

 /** ProcType Declarations of the TextWriter2 component */ 
active proctype run_2() {
  TWEvent requestEvent,releaseEvent;
  requestEvent.source=2;
  requestEvent.isRequest = true;
  releaseEvent.source=2;
  releaseEvent.isRequest = false;
  TextUpdateEvent textEvent;
  textEvent.source=2;

  LOOP:
  receiveTWEvent_1(requestEvent);
  atomic {(notify_2==true) -> notify_2=false;}
  receiveTextUpdateEvent_3(textEvent);
  receiveTWEvent_1(releaseEvent);
  goto LOOP
} 


