Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A protected object to do the three operations might look something like this. But note, all this does is make sure that the three variables x, y and z are consistent with the order that the updates occurred in; it says nothing about the order.</p> <pre><code> protected P is procedure Update_X; procedure Update_Y; procedure Update_Z; function Get_Z return Integer; private X : Integer := 0; Y : Integer := 0; Z : Integer := 0; end P; protected body P is procedure Update_X is begin X := X + 1; end Update_X; procedure Update_Y is begin Y := Y + X; end Update_Y; procedure Update_Z is begin Z := X + Y + Z; end Update_Z; function Get_Z return Integer is begin return Z; end Get_Z; end P; </code></pre> <p>On the other hand, to make sure that the three tasks "submit their results" in the proper order, you could rewrite P so that a call to say Update_Y will block until Update_X has been called: Get_Z now has to be an entry with an out parameter rather than a function.</p> <pre><code> protected P is entry Update_X; entry Update_Y; entry Update_Z; entry Get_Z (Result : out Integer); private X_Updated : Boolean := False; Y_Updated : Boolean := False; Z_Updated : Boolean := False; X : Integer := 0; Y : Integer := 0; Z : Integer := 0; end P; protected body P is entry Update_X when True is begin X := X + 1; X_Updated := True; end Update_X; entry Update_Y when X_Updated is begin Y := Y + X; Y_Updated := True; end Update_Y; entry Update_Z when Y_Updated is begin Z := X + Y + Z; Z_Updated := True; end Update_Z; entry Get_Z (Result : out Integer) when Z_Updated is begin Result := Z; end Get_Z; end P; </code></pre> <p>The three tasks can now have any priority you like. But the task that calls Update_Z will block until the other two have reported.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload