How can I use threads in Ada95? What functions can I use to create, destroy, stop and start them?
How can I use semaphores in this language?
Concurrency is built into the language, so you have specific Ada syntax for tasks (i.e. threads) and protected objects (i.e. which are more powerful than semaphores / mutexes / conditional variables). This makes much easier (and less error prone) programming multi-threaded apps in Ada than in other languages like C / Java.
It's not recommended to use semaphores in Ada, protected objects are much more powerful (but you can build semaphores easily using protected objects if needed).
Some small syntax examples. Tasks (and protected objects) can be static...
task My_Task;
task body My_Task is
begin
-- Just print this to stdout and exit thread
Ada.Text_IO.Put_Line("Hello, concurrent World!");
end;
...or created dynamically
task type My_Task_Type(N : Natural);
task body My_Task_Type(N : Natural) is ...
...
T1 := new My_Task_Type(100);
abort T1;
Much less verbose than other languages (and more maintenable)! See 'new', and 'abort' keywords for managing dynamic tasks, as well as other specialized packages like Ada.Synchronous_Task_Control.
Ada's terminology for a thread is a "task". Ada doesn't have semaphores (as such) built directly into the language, but Googling for something like "Ada semaphore" should turn up a fair number of hits. AdaPower.com, in particular, has quite a bit about concurrent programming in Ada (and, for that matter, almost all kinds of programming in Ada).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With