CATEGORII DOCUMENTE |
Shared int I=0; Shared int I;
While true do While true do
Procesare_necritica; Procesare_necritica;
While (I<>0) do; While (I<>0) do;
I=1; I=1;
Procesare_exclusiva; Procesare_exclusiva;
I=0; I=0;
EndWhile EndWhile
Shared int I=0; Shared int I;
While true do While true do
Procesare_necritica; Procesare_necritica;
While (I<>1) do While (I<>2) do
If I=0 Then I=1; If I=0 Then I=2;
Procesare_critica; Procesare_critica;
I=0; I=0;
EndWhile EndWhile
Shared int turn=0; Shared int turn=0;
while (TRUE) }
Region V do statement;
DeclareRegion V;
While true do While true do
Procesare_necritica; Procesare_necritica;
Region V do Region V do
Procesare_exclusiva; Procesare_exclusiva;
EndWhile EndWhile
Shared Data;
Shared status = EMPTY;
Region V;
While true do
Produce(item);
Succeded = 0;
While Succeded = 0 do
Region V do
If status = EMPTY then
Data = item;
Status = FULL;
Succeded = 1;
Endif
EndWhile
EndWhile
Shared Data;
Shared status = EMPTY;
Region V;
While true do
Succeded = 0;
While Succeded = 0 do
Region V do
If status = FULL then
Item = Data;
Status = EMPTY;
Succeded = 1;
Endif
EndWhile
Consume(item);
EndWhile
When Conditie Region V Do Statement;
Shared Data;
Shared status = EMPTY;
Region V;
While true do
Produce(item);
When status = EMPTY Region v Do
Data = item;
Status = FULL;
EndWhen
EndWhile
Shared Data;
Shared status = EMPTY;
Region V;
While true do
When status = FULL Region v Do
Item = Data;
Status = EMPTY;
EndWhen
Consume(item);
EndWhile
#define N 100 / number of slots in the buffer
semaphore mutex = 1;
semaphore empty = N;
semaphore full = 0;
void producer(void)
void consumer(void)
Shared contor_sem;
Region v;
UP()
DOWN()
Object o;
Synchronized(o)
Synchronized(o)
Synchronized(o)
Synchronized(o)
Class semafor
synchronized DOWN()
#define N 5 / number of philosophers
semaphore forks[N] := 1; /* all initially free */
void philosopher(int i)
void take_fork(int i)
void put_fork(int i)
#define N 5 / number of philosophers
void philosopher(int i)
#define N 5
#define LEFT (i+N1)%N
#define RIGHT (i+1)%N
#define THINKING 0
#define HUNGRY 1
#define EATING 2
int state[N];
semaphore mutex = 1;
semaphore s[N];
void philosopher(int i)
void take_forks(int i)
void put_forks(i)
void test(i)
Task task1;
Select
When conditie1 => accept point1(parametrii) do statement1;
Statement2;
When conditie2 => accept point2(parametrii) do statement3;
Statement4;
Else
Statement5;
End select;
End task;
Task task2;
task1.point2(parametrii);
end task.
Task semafor;
Int i=0;
While true do
Select
When i>0 accept DOWN() do i--;
When true accept UP() do i++;
End select
End while
End task.
shared ST_FIL[0..N-1] = THINK;
shared ST_FORK[0..N-1] = ON_TABLE;
task TABLE;
while true do
x = -1;
select
when true TEST(fil) do
if ST_FILE[fil] == HUNGRY and
ST_FORK[fil] == ON_TABLE and
ST_FORK[(fil+1)%N] == ON_TABLE
then
x = fil;
endif
endwhen
when true PUT(fil) do
ST_FORK[fil] == ON_TABLE
ST_FORK[(fil+1)%N] == ON_TABLE
endwhen
endselect
if x >= 0 then
ST_FORK[x] = TAKEN;
ST_FORK[(x+1)%N] = TAKEN;
FIL[x].CAN_EAT();
endif
endwhile
endtask
task FIL[I=0..N-1];
while true do
ST_FIL[I]=HUNGRY;
TABLE.TEST(fil);
select
when true CAN_EAT() do
ST_FIL[I]=EAT;
endwhen
endselect
EAT();
ST_FIL[I]=THINK;
TABLE.PUT(I);
TABLE.TEST((I-1)%N);
TABLE.TEST((I+1)%N);
THINK();
endwhile
endtask
shared ST_FIL[0..N-1] = THINK;
shared ST_FORK[0..N-1] = ON_TABLE;
task TABLE;
while true do
x = -1;
select
when true TEST(type, fil) do
if type == SAME then
ST_FIL[fil]=HUNGRY
endif
if ST_FILE[fil] == HUNGRY and
ST_FORK[fil] == ON_TABLE and
ST_FORK[(fil+1)%N] == ON_TABLE
then
x = fil;
endif
endwhen
when true PUT(fil) do
ST_FORK[fil] == ON_TABLE
ST_FORK[(fil+1)%N] == ON_TABLE
endwhen
endselect
if x >= 0 then
ST_FORK[x] = TAKEN;
ST_FORK[(x+1)%N] = TAKEN;
FIL[x].CAN_EAT();
endif
endwhile
endtask
task FIL[I=0..N-1];
while true do
TABLE.TEST(SAME, fil);
select when true CAN_EAT() do
ST_FIL[I]=EAT;
endwhen; endselect;
EAT();
ST_FIL[I]=THINK;
TABLE.PUT(I);
TABLE.TEST(OTHER, (I-1)%N);
TABLE.TEST(OTHER, (I+1)%N);
THINK();
endwhile
endtask
Politica de confidentialitate | Termeni si conditii de utilizare |
Vizualizari: 2056
Importanta:
Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved