(+84) 236.3827111 ex. 402

Phép toán thực hiện đồng thời


Phép toán thực hiện đồng thời

Cú pháp:

<Concurrency> ::= Concurrency(, , , , ,

<>_expression>,)

Ví dụ:

Concurrency(TaskA,TaskB,PA0,Cond1,PA1,cond2,PA2,…,Condn,PAn)

Trong đó 0< PAi <1 iÎ[0,n], condi Îbool,condi là các biên kiểu boolean.

Hoạt động của phép toán được trình bày như sau:

do

begin

n= rand(1)

if (Cond1== TRUE)

if (n<= PA1) Action_From_TaskA;

else Action_from_TaskB;

else if (Cond2== TRUE)

if (n<= PA2) Action_From_TaskA;

else Action_from_TaskB;

else if (Condn== TRUE)

if (n<= PAn) Action_From_TaskA;

else Action_from_TaskB;

else

if (n<= PA0) Action_from_TaskA;

else Action_from_TaskB;

if TaskA is finished

all remaining actions of TaskB are executed;

if TaskB is finished

all remaining actions of TaskA are executed;

end;

while (all actions from taskA and TaskB haven’t executed yet)