Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with ada.Text_IO;
- use ada.Text_IO;
- with ada.Integer_Text_IO;
- use ada.Integer_Text_IO;
- procedure Main is
- task type mytask;
- task type mytask1;
- th1: mytask;
- th2: mytask1;
- task type Semaphore_T is
- entry Initialize(n : Natural);
- entry Wait;
- entry Signal;
- end Semaphore_T;
- task body Semaphore_T is
- Count: Natural;
- begin
- accept Initialize(n: in Natural) do
- Count := n;
- end Initialize;
- loop
- select
- when Count>0 =>
- accept Wait do
- Count := Count - 1;
- end Wait;
- or
- accept Signal do
- Count := Count + 1;
- end Signal;
- end select;
- end loop;
- end Semaphore_T;
- sem_Z : Semaphore_T;
- sem_W : Semaphore_T;
- type Bufor is array(Natural Range<>) of Integer;
- buf: Bufor(1..5);
- --WATEK CZYTAJACY
- task body mytask is
- a: Integer;
- odczytana: Integer;
- begin
- a:=1;
- loop
- sem_Z.Wait;
- odczytana:= buf((a rem 5) +1) ;
- Put(odczytana);
- sem_W.Signal;
- a:= a+1;
- end loop;
- end mytask;
- task body mytask1 is
- a: Integer;
- do_zapisu: Integer;
- begin
- do_zapisu:=100;
- a:=1;
- loop
- sem_W.Wait;
- buf((a rem 5) +1) := do_zapisu;
- sem_Z.Signal;
- do_zapisu:=do_zapisu+3;
- a:= a+1;
- end loop;
- end mytask1;
- begin
- sem_W.Initialize(5);
- sem_Z.Initialize(0);
- null;
- end Main;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement