with Text_io, IIO; use Text_io; procedure SIEVE is -- C A R Hoare's Prime Number Sieve - using Tasks task type PRIMES is entry Get(ID:positive; NUMBER:positive);-- ID identifes which prime entry STOP; end PRIMES; type APRIMES is access PRIMES; ANSWER:string(1..1); P2:PRIMES; procedure MAKE_PRIME(N:in out APRIMES) is begin if N=null then N:=new PRIMES; end if; end; procedure DBG(S:string) is begin Put("Debug: "); Put_line(S); end DBG; procedure DBG(N:positive) is begin Put("Debug: "); IIO.Put(N); New_line; end DBG; procedure DBG(S:string; N:positive) is begin Put("Debug: " & S); IIO.Put(N); New_line; end DBG; procedure DBG(S:string; P,N:positive) is begin Put("Debug: " & S); IIO.Put(P);Put(":");IIO.Put(N); New_line; end DBG; task body PRIMES is separate; begin for N in 2..67 loop -- DBG("MAIN n= ",N); P2.Get(ID=>1, NUMBER=>N); end loop; --DBG("MAIN STOP"); P2.STOP; end SIEVE; -------------------------------------------- separate(SIEVE) task body PRIMES is P:positive; -- This task's PRIME NUMBER. I:positive; -- Prime Number (I). N:positive; DONE:boolean; NEXT:APRIMES; begin --DBG("P"); accept Get(ID:positive; NUMBER:positive) do P:=NUMBER; I:=ID; IIO.Put(I);Put("th Prime is ");IIO.Put(P);New_line; end Get; select accept Get(ID:positive; NUMBER:positive) do N:=NUMBER; DONE:=false; end Get; or accept STOP do DONE:=true; end STOP; end select; --DBG("P",N); if not DONE then MAKE_PRIME(NEXT); loop --DBG("P",P,N); if N mod P /= 0 then NEXT.Get(ID=>I+1, NUMBER=>N); end if; select accept Get(ID:positive; NUMBER:positive) do N:=NUMBER; DONE:=false; end Get; or accept STOP do DONE:=true; end STOP; end select; exit when DONE; end loop; --DBG("end loop in P",P); NEXT.STOP; end if; --DBG ("end of P",P); end;