Untitled

From Chunky Tern, 12 Years ago, written in Plain Text, viewed 5 times.
URL https://paste.blessuren.de/view/747af76f Embed
Download Paste or View Raw
  1. #define N 10
  2. #define K  5
  3.  
  4. mtype = {send,term,ack,termack,repeat,termrepeat};
  5. chan c12 = [0] of {mtype,byte};
  6. chan c23 = [0] of {mtype,byte};
  7. chan c32 = [0] of {mtype,byte};
  8. chan c21 = [0] of {mtype,byte};
  9.  
  10. byte p1Sum = 0;
  11. byte p2Sum = 0;
  12. byte p3Sum = 0;
  13.  
  14. active proctype P1(){
  15.         byte termackval=0;
  16.         byte ackval=0;
  17.         byte wert=1;
  18.         byte antwort;
  19.        
  20.         do
  21.         :: wert<=N -> atomic{c12!send,wert; p1Sum = p1Sum + wert; wert = wert+1;}
  22.                 if
  23.                 /* auf ack warten */
  24.                 ::c21?ack,ackval -> printf("ack von P2 erhalten")
  25.                 /* ist nicht angekommen */
  26.                 ::c21?repeat,wert -> c12!send,wert;    
  27.                 fi
  28.         :: wert > K -> break;
  29.         od;
  30.        
  31.         c12!term,0;
  32.        
  33.         do
  34.         :: c21?termrepeat,wert -> c12!term,0;
  35.         :: c21?termack,termackval -> break;
  36.         od
  37. }      
  38.  
  39. active proctype P2(){
  40.         byte ein=0;
  41.         byte ackval=0;
  42.         byte termackval=0;
  43.         do
  44.         :: c12?send,ein -> atomic {p2Sum = p2Sum + ein; c21!ack,ein};c23!send,ein;
  45.                         if
  46.                         :: c32?ack,ackval -> printf("ack von P3 erhalten")
  47.                         :: c32?repeat,ein -> c23!send,ein;
  48.                         fi
  49.         :: c12?send,ein -> c21!repeat,ein; skip
  50.         :: c12?term,ein -> atomic {c21!termack,ein; c23!term,ein;}
  51.                         if
  52.                         :: c32?termack,termackval -> break;
  53.                         :: c32?termrepeat,ein -> c23!term,ein;
  54.                         fi                 
  55.         :: c12?term,ein -> c21!termrepeat,ein;
  56.         od;
  57. }
  58.  
  59. active proctype P3(){
  60.         byte ein=0;
  61.         do
  62.         :: c23?send,ein ->
  63.                 atomic {p3Sum = p3Sum + ein; c32!ack,ein;}
  64.         :: c23?send,ein ->
  65.                 c32!repeat,ein;
  66.         :: c23?term,ein ->
  67.                 atomic {c32!termack,ein; break;}
  68.         :: c23?term,ein ->
  69.                 c32!termrepeat,ein; skip
  70.         od;
  71. }
  72.  
  73. active proctype Invariante() {
  74.         assert(p1Sum <= 55 && p2Sum <= 55 && p3Sum <= 55);
  75. }

Reply to "Untitled"

Here you can reply to the paste above