   { abaab-2sem.pm -- program ktery vypise ABAAB pomoci dvou semaforu }
   program abaab;

   var s: semaphore := 0;
       t: semaphore := 0;

   procedure xx; { procedura xx vypise, ktery proces ji zavolal }
   var p: integer;
   begin
        p := which_proc;
        if p=1 then write('A')
        else if p=2 then write('B')
        else write('?')
   end;

   procedure A;
   begin
        xx;
        V(s);
        P(t);
        xx;
        xx;
        V(s)
   end;

   procedure B;
   begin
        P(s);
        xx;
        V(t);
        P(s);
        xx
   end;

begin
     cobegin 
            a; b 
     coend;
     writeln
end.
