Concurrent computing: Difference between revisions

Content deleted Content added
→‎{{header|C++}}: Added C++ implementation
m →‎{{header|Ada}}: Not null constraint added (Ada 2005)
Line 7: Line 7:


procedure Concurrent_Hello is
procedure Concurrent_Hello is
task type Writer (Message : access String);
task type Writer (Message : not null access String);
task body Writer is
task body Writer is
Seed : Generator;
Seed : Generator;
begin
begin
Reset (Seed); ''-- This is time-dependent, see Reference Manual A.5.2''
Reset (Seed); -- This is time-dependent, see ARM A.5.2
delay Duration (Random (Seed));
delay Duration (Random (Seed));
Put_Line (Message.all);
Put_Line (Message.all);
Line 26: Line 26:
end Concurrent_Hello;</lang>
end Concurrent_Hello;</lang>


Note that random generator object is local to each task. It cannot be accessed concurrently without mutual exclusion. In order to get different initial states of local generators Reset is called.
Note that random generator object is local to each task. It cannot be accessed concurrently without mutual exclusion. In order to get different initial states of local generators Reset is called (see [http://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-5-2.html ARM A.5.2]).


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==