Multitasking in ADA

How multitasking is achieved in ADA. Please look at the following pseudo code


 

Procedure ABC

task A  

task body A is

——-

End A

task B

task body B is

——-

End A

task C  

task body Cis

——-

End C

Begin

–  Procedure ABC's statements

End ABC

 
 

In the above code, when the procedure begins all the three tasks A,B and C initiated concurrently and when the procedure ends, all the tasks completes their execution.  The three tasks does not have any relation with one another (means all are independent tasks)

 
 

Suppose if the tasks are having some relations between each other, then the following code depicts their behavior.

Procedure SHARING

Task A;

Task Body A is

B.BETA(X);

C.GAMMA(X);

End A;

Task B is

                Entry BETA(X:float);

Task Body B is

                Accept BETA(X:float);

End B;

Task C is

                Entry GAMMA(X:float);

Task Body C is

                Accept GAMMA(X:float);

End C;

Begin

End SHARING;

 
 

In the above code, the task A wants to share a float variable X at a point ALPHA with the tasks B and C at the points BETA and GAMMA respectively. When the procedure SHARING starts, all the three tasks initiated concurrently and if the task A reaches ALPHA first, it will to share the information with B and C and it will wait. If B reaches BETA first, it will also wait for ALPHA to reach. Similarly if C reaches GAMMA first, it will also wait for A and B to reach ALPHA and GAMMA respectively.

Comments

Popular Posts