# How does async/concurrency work in ADA compared to other languages?

**URL:** <https://forum.ada-lang.io/t/how-does-async-concurrency-work-in-ada-compared-to-other-languages/2247>\
**Category:** General\
**Created:** [July 26, 2025, 4:49pm UTC](https://forum.ada-lang.io/t/how-does-async-concurrency-work-in-ada-compared-to-other-languages/2247 "2025-07-26T16:49:25Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![ValorZard](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/valorzard/32/623_2.png) [@ValorZard](https://forum.ada-lang.io/u/ValorZard)\
**Post date:** [July 26, 2025, 4:49pm UTC](https://forum.ada-lang.io/t/how-does-async-concurrency-work-in-ada-compared-to-other-languages/2247/1 "2025-07-26T16:49:25Z")

</div>

Hello again!  
Something I’ve been really interested in is concurrency in different languages. A lot of my experience has been in Rust with Tokio and async/await, but I have a decent amount of experience with go as well.

Additionally, Zig recently came out with their new Async feature which is quite unique: [Zig's New Async I/O | Loris Cro's Blog](https://kristoff.it/blog/zig-new-async-io/)

Which leads me to wonder about Ada. From what I can tell, Ada has tasks. Do they work like Tokio or C# tasks? Is structured concurrency a thing?

Like, to come up with a contrived example, how would having a server that listening to oncoming connections work? In Tokio, I could see spawning a task for each oncoming connection, and then making a channel for each task to communicate with it.

Are green threads/virtual threads a thing/possible in ADA? Are stackless coroutines?

---

<div class="post-metadata">

**Author:** ![ValorZard](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/valorzard/32/623_2.png) [@ValorZard](https://forum.ada-lang.io/u/ValorZard)\
**Post date:** [July 26, 2025, 5:05pm UTC](https://forum.ada-lang.io/t/how-does-async-concurrency-work-in-ada-compared-to-other-languages/2247/2 "2025-07-26T17:05:48Z")

</div>

I should also probably share how coroutines work in C++ [Coroutines (C++20) - cppreference.com](https://en.cppreference.com/w/cpp/language/coroutines.html)

---

<div class="post-metadata">

**Author:** ![jere](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/jere/32/87_2.png) [@jere](https://forum.ada-lang.io/u/jere)\
**Post date:** [July 26, 2025, 5:54pm UTC](https://forum.ada-lang.io/t/how-does-async-concurrency-work-in-ada-compared-to-other-languages/2247/3 "2025-07-26T17:54:32Z")

</div>

I’m not super huge into the async world, so I can’t really give details on that, but I will say that Ada has a lot of options for how you want to manage your concurrency.

If you want to block on a task entry, you simply call it and the calling program will block until that entry is ready to run:

```Ada
Some_Task.Action;

```

If you still want it to block, but not indefinitely, you can do a [timed entry call](http://www.ada-auth.org/standards/22rm/html/RM-9-7-2.html):

```Ada
select
   Some_Task.Action;
   -- You can do additional things here after successful action
or
   delay 5.0; -- Wait up to 5sec or give up
   -- You can do other things here if it times out
end select;
-- Stuff here happens regardless of time out or not

```

If you don’t want to block at all but want to try and then leave, you can use a [conditional entry call](http://www.ada-auth.org/standards/22rm/html/RM-9-7-3.html):

```Ada
select
   Some_Task.Action;
   -- You can do additional things here after successful action
else
   -- You can do other things here if the action wasn't ready
end select;
-- Stuff here happens regardless of success or not

```

These also work with `entry` calls to protected objects in addition to task entries. I think the conditional entry call is probably the means one would implement an async call, but again, I’m not really into the async world, so grain of salt.

Ada also has “rendezvous” where two different tasks meet, some shared code is run, then the tasks each go about their business. It’s a pretty neat model that can be leveraged for some interesting solutions to tasking/threading problems.

```Ada
task body Some_Task is
begin
   loop
      select
         accept Action(Input_Data : in Input_Type; Output_Data : out Output_Type) do
            -- Code in here is "task safe" relative to this task vs the calling task
            -- since both the calling task and this task meet here and wait until 
            -- the "end" is reached before continuing.
         end Action;
         -- Other statements not guarded by the rendezvous
      or
         accept Some_Other_Action;
         -- Other statements not guarded by the rendezvous
      end select;
   end loop;
end Some_Task;

```

Sorry I don’t have any async specific stuff, but you seem knowledgeable on it, so I was hoping it can it least give you some things to think about.

There’s also a lot of others features like entry barriers that let you set conditions to actually do the task’s entry and lots of other things.

EDIT: I don’t know how into books you are, but I really liked this one:

> **[Concurrent and Real-Time Programming in Ada 3rd, Burns, Alan, Wellings, Andy,...](https://www.amazon.com/Concurrent-Real-Time-Programming-Alan-Burns-ebook/dp/B001GS6TBO)**
>
> Concurrent and Real-Time Programming in Ada - Kindle edition by Burns, Alan, Wellings, Andy. Download it once and read it on your Kindle device, PC, phones or tablets. Use features like bookmarks, note taking and highlighting while reading Concurrent...

It’s based on the 2012 version of Ada, but it’s still really relevant.

---

<div class="post-metadata">

**Author:** ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)\
**Post date:** [July 26, 2025, 7:13pm UTC](https://forum.ada-lang.io/t/how-does-async-concurrency-work-in-ada-compared-to-other-languages/2247/4 "2025-07-26T19:13:14Z")

</div>

Differently to other languages Ada has integrated concurrency primitives. For decades “newer” languages simply ignored concurrency. Now they try to add it, but still at a very low level abstraction. Ada’s concurrency is high level. It has protected objects and tasks. The model is safer and more effective. In particular you can implement all low level primitives like mutexes, events (level and pulse), semaphores on top of Ada’s ones.

> [@ValorZard](#):
>
> Which leads me to wonder about Ada. From what I can tell, Ada has tasks. Do they work like Tokio or C# tasks? Is structured concurrency a thing?

Ada tasks allow many implementations. The most frequent implementation is tasks backed by system threads.

> [@ValorZard](#):
>
> Are green threads/virtual threads a thing/possible in ADA?

Yes, as one of the tasking models you would not like to use because doing blocking I/O from such a tread would block all other threads. It sometimes deployed on bare-bone embedded systems.

> [@ValorZard](#):
>
> Are stackless coroutines?

Ada does not have co-routines. It is worth to note that stackless co-routines are totally useless for practical purposes.

> [@ValorZard](#):
>
> Like, to come up with a contrived example, how would having a server that listening to oncoming connections work? In Tokio, I could see spawning a task for each oncoming connection, and then making a channel for each task to communicate with it.

Yes, you can trivially do that in Ada: accept connection, create or reuse a task, pass the socket to it. Task is just an object in Ada.

But in general it does not scale because having a task per connection is too heavy for small targets or massive number of connections. So a better solution is to use a single task asynchronously managing several sockets and handling connections. Additionally one can have a pool of tasks to handle connection requests. You can find an implementation of this approach [here](https://www.dmitry-kazakov.de/ada/components.htm#multiple_GNAT.Sockets.Servers).

---

<div class="post-metadata">

**Author:** ![pyj](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/pyj/32/5_2.png) [@pyj](https://forum.ada-lang.io/u/pyj)\
**Post date:** [July 26, 2025, 7:19pm UTC](https://forum.ada-lang.io/t/how-does-async-concurrency-work-in-ada-compared-to-other-languages/2247/5 "2025-07-26T19:19:02Z")

</div>

The best resource might be [the AdaCore tutorial on tasking](https://learn.adacore.com/courses/intro-to-ada/chapters/tasking.html#)

Tasking is a really deep subject, I’ve used it only a little bit, but I will do my best to highlight the big points.

## High level

Ada uses the `task` keyword for concurrency. It defines a declaration area and a block of code to run. IME using GNAT, that means “task = thread”.

A task runs concurrently in the scope it’s declared in, and that scope won’t exit until it finishes. This is similar to “jthreads” from C++. If you want a task to live longer than that, you need to dynamically allocate it.

`task` is defined by the language and obeys lexical scoping rules. Anything visible at the scope of a task can be used by that task. You can also pass data into a task by declaring it with a discriminant.

Ada provides a [monitor](https://en.wikipedia.org/wiki/Monitor_(synchronization)) like element, called a “protected object.” A function in a protected object can only read, but a procedure can read-or-write that protected object’s data.

Sometimes you want a guard before operating on some data, or you want to provide a way for multiple threads to coordinate or pass data. This is what “entries” do, they look like `procedure`s or `function`s, but like procedures, they have no return type.

There isn’t a fire-and-forget async/await system like in Rust or C#, though I think you probably might be able to build one using the language primitives.

## Simple task example

Trendy\_Test runs a bunch of test executors in parallel. The task is actually declared _inside_ the `Run` subprogram:

```ada
function Run return Test_Report_Vectors.Vector is
    Results : Test_Results; -- thread-safe type to combine results
    Tests : Test_Queues.Queue; -- thread-safe queue of parallel tests

    task type Parallel_Test_Task is end Parallel_Test_Task;
    task body Parallel_Test_Task is
        Next_Test : Test_Procedure;
    begin
        loop
            select
                Tests.Dequeue (Next_Test);
            or
                delay 0.1;
                exit;
            end select;

            Run_Test (Next_Test, Results);
        end loop;
    end Parallel_Test_Task;

```

Starting all parallel threads for running parallelizable tests within `Run` looks like this:

```ada
declare
    Num_CPUs : constant System.Multiprocessors.CPU := System.Multiprocessors.Number_Of_CPUs;
    Runners : array (1 .. Num_CPUs) of Parallel_Test_Task;
    pragma Unreferenced (Runners);
begin
    -- Tests have started when declared above, wait for runners to complete.
    null;
end;

```

In this example `Tests` and `Results` are both protected objects which act to prevent the tasks from accessing shared state at the same time.

`Test_Results` is super straightforward, and requires no manual locking (if you’re familiar with using `std::mutex` or RAII read or write lock objects). By making `Add` a procedure it can read/write the `Results` vector. If I try to write in `Get_Results` which is a `function` which only has read access, it’s a compile-time error.

```ada
protected type Test_Results is
    procedure Add(T : Test_Report);
    function Get_Results return Test_Report_Vectors.Vector;
private
    Results : Test_Report_Vectors.Vector;
end Test_Results;

```

## Entries

Entries are like procedures, but can have guards forcing callers to wait and have associated queues of who is waiting for them. The [Jorvik](https://blog.adacore.com/introduction-to-jorvik) and [Ravenscar](https://en.wikipedia.org/wiki/Ravenscar_profile) profiles are subsets of Ada tasking that describe agreed upon limits of tasking features like max queue length.

An entry defined on a `task` or `protected` object looks just like a procedure call. However, it doesn’t proceed until the guard is true on a protected object, or the task calls `accept` on that entry, which is what @jere shows above.

## Overall

My experience with using tasks/protected objects on multiple projects is that they seem to work well. I’ve run into some issues because it’s baked into the language about wanting more introspection into what’s actually going on. Concurrency in general is also hard and I’m also not the sharpest crayon in the box, so maybe my code has all sorts of concurrency bugs I don’t know about /shrug.

---

<div class="post-metadata">

**Author:** ![Lucretia](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/lucretia/32/17_2.png) [@Lucretia](https://forum.ada-lang.io/u/Lucretia)\
**Post date:** [July 26, 2025, 7:39pm UTC](https://forum.ada-lang.io/t/how-does-async-concurrency-work-in-ada-compared-to-other-languages/2247/6 "2025-07-26T19:39:17Z")

</div>

I remember gnat having a green threads lib you could select in 1995, not any more though.

---

<div class="post-metadata">

**Author:** ![ValorZard](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/valorzard/32/623_2.png) [@ValorZard](https://forum.ada-lang.io/u/ValorZard)\
**Post date:** [July 27, 2025, 12:12am UTC](https://forum.ada-lang.io/t/how-does-async-concurrency-work-in-ada-compared-to-other-languages/2247/7 "2025-07-27T00:12:38Z")

</div>

Thanks for all the answers!  
I heard that Ada 2022 has a new “parallel” keyword that hasn’t been implemented yet.

> **[Google Summer of Code](https://summerofcode.withgoogle.com/programs/2025/projects/Ex0T0sK7)**
>
> Google Summer of Code is a global program focused on bringing more developers into open source software development.

How does this interact with all of the currently existing task stuff

---

<div class="post-metadata">

**Author:** ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)\
**Post date:** [July 27, 2025, 4:46pm UTC](https://forum.ada-lang.io/t/how-does-async-concurrency-work-in-ada-compared-to-other-languages/2247/8 "2025-07-27T16:46:06Z")

</div>

> [@ValorZard](#):
>
> How does this interact with all of the currently existing task stuff

It will not. Parallel loops are symmetric fine-grained parallelism, tasks and protected objects are for asymmetric bulky one.

In my understanding “parallel” would naturally have a quite limited use, but may potentially provide a huge performance gain when backed by FPGA hardware or similar.

---

<div class="post-metadata">

**Author:** ![sidisyom](https://forum.ada-lang.io/letter_avatar_proxy/v4/letter/s/5fc32e/32.png) [@sidisyom](https://forum.ada-lang.io/u/sidisyom)\
**Post date:** [August 3, 2025, 2:29pm UTC](https://forum.ada-lang.io/t/how-does-async-concurrency-work-in-ada-compared-to-other-languages/2247/9 "2025-08-03T14:29:43Z")

</div>

FWIW, one difference between Ada and one other language like Java is that Ada follows the model of _avoidance-synchronisation_ whereas Java that of _condition-synchronisation_. Effectively, these are different strategies applied when trying to decide whether the right conditions exist for a task/thread to execute whatever logic it’s meant to execute.

For example, suppose a very simple buffer which in Ada could be implemented as a protected object (PO) (other ways exist). Normally, something like the following would be declared:

```ada
protected type Buffer is
   entry Has_New_Data;
   procedure Set_New_Data (D : Interfaces.Unsigned_64);
private
   New_Data : Boolean := False;
   Data : Interfaces.Unsigned_64;
end Buffer;

protected body Buffer is
   entry Has_New_Data when New_Data is
   begin
      New_Data := False;
   end Has_New_Data;

   procedure Set_New_Data (D : Interfaces.Unsigned_64) is
   begin
      Data := D;
      New_Data := True;
   end Set_New_Data;
end Buffer;

```

What happens here is that when the `when New_Data` barriers evaluates to `True` (and the monitor has been acquired) the _runtime_ guarantees that the condition is unequivocally true so one of the blocked tasks is allowed to continue and execute the PO code (which ones depends on the specific annexes that are active in the runtime). The big advantage with that is that the PO code doesn’t need to check itself whether the condition is actually true indeed, so the block inside the entry only contains logic related to the happy-path scenario. This, imo, is great cause it allows a reader to easily follow through the normal flow without having to navigate through a number of lines which are totally unrelated to what should happen when some condition is true.

Java, on the other hand, takes a different approach, that of condition-synchronisation, whereby the code _itself_ needs to check whether a condition is true in order to determine if it can proceed or not. What’s worse is that the JVM has something called “spurious-wakeups” where the runtime can basically make a blocked thread runnable for totally unrelated reasons. So, in addition to the main condition-checking, the code needs to _also_ manually check whether the data related to the condition are correct indeed, every time a thread is made runnable.  
So, the equivalent of the above example would be something like this in Java (showing only the first part):

```ada
private Lock lock = new ReentrantLock();
private Condition newDataCond = lock.newCondition();
private boolean newData = false;

public void hasNewData() {
    lock.lock();
    try {
    // Check conditions are right in order to proceed, here
    while (!newData) {
        try {
            newDataCond.await();
        } catch (InterruptedException e) {
            // maybe also log
            throw new RuntimeException(e);
        }
    }
    // Happy-path logic, here
    } finally {
        lock.unlock();
    }
}

```

where the `while` loop has been setup to guard against the spurious-wakeups mentioned above.

The price to pay for Ada’s simplicity, is that entry arguments aren’t allowed to be used in the barrier condition, which in some cases can be limiting. But this issue can be solved (perhaps more elegantly) using the `requeue` feature.

---

<div class="post-metadata">

**Author:** ![ValorZard](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/valorzard/32/623_2.png) [@ValorZard](https://forum.ada-lang.io/u/ValorZard)\
**Post date:** [December 4, 2025, 5:57pm UTC](https://forum.ada-lang.io/t/how-does-async-concurrency-work-in-ada-compared-to-other-languages/2247/10 "2025-12-04T17:57:09Z")

</div>

Hi again!

Sorry to necro this thread, but I’m curious, how would you translate this code into ADA?

(Taken from here: [A Tour of Go](https://go.dev/tour/concurrency/4))

> package main
> 
> import (  
> “fmt”  
> )
> 
> func fibonacci(n int, c chan int) {  
> x, y := 0, 1  
> for i := 0; i \< n; i++ {  
> c ← x  
> x, y = y, x+y  
> }  
> close(c)  
> }
> 
> func main() {  
> c := make(chan int, 10)  
> go fibonacci(cap(c), c)  
> for i := range c {  
> fmt.Println(i)  
> }  
> }

---

<div class="post-metadata">

**Author:** ![Lucretia](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/lucretia/32/17_2.png) [@Lucretia](https://forum.ada-lang.io/u/Lucretia)\
**Post date:** [December 4, 2025, 5:57pm UTC](https://forum.ada-lang.io/t/how-does-async-concurrency-work-in-ada-compared-to-other-languages/2247/11 "2025-12-04T17:57:58Z")

</div>

look at parallel and gcc-16.

---

<div class="post-metadata">

**Author:** ![ValorZard](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/valorzard/32/623_2.png) [@ValorZard](https://forum.ada-lang.io/u/ValorZard)\
**Post date:** [December 4, 2025, 7:59pm UTC](https://forum.ada-lang.io/t/how-does-async-concurrency-work-in-ada-compared-to-other-languages/2247/12 "2025-12-04T19:59:39Z")

</div>

I can’t seem to find a lot of information on that.

I found this reddit post ([https://www.reddit.com/r/ada/comments/1otyt0s/ada\_2022\_parallel\_implementation\_beta\_for\_fsf/](https://www.reddit.com/r/ada/comments/1otyt0s/ada_2022_parallel_implementation_beta_for_fsf/)) and this page ([Parallel constructs](http://ada-auth.org/standards/22over/html/Ov22-2-1.html)) from what looks like the standard, but that’s about it

Edit: I also found this library which seems like the main implementation for the parallel keyword? ([parasail/lwt at main · parasail-lang/parasail · GitHub](https://github.com/parasail-lang/parasail/tree/main/lwt))

---

<div class="post-metadata">

**Author:** ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)\
**Post date:** [December 4, 2025, 8:23pm UTC](https://forum.ada-lang.io/t/how-does-async-concurrency-work-in-ada-compared-to-other-languages/2247/13 "2025-12-04T20:23:21Z")

</div>

Here is an implementation from [Simple Components](https://www.dmitry-kazakov.de/ada/components.htm#Unbounded_Unsigneds) that uses the square splitting algorithm:

```ada
   function Fibonacci (N : Natural) return Unbounded_Unsigned is
      --
      -- F(2k) = F(k)(2F(k+1)) - F(k))
      -- F(2k+1) = F(k+1)*F(k+1) + F(k)*F(k)
      --
      A, B, D, E : Unbounded_Unsigned;
      M : Natural := N;
      Bit : Natural := 1;
   begin
      while M > 0 loop
         Bit := Bit * 2;
         M := M / 2;
      end loop;
      Set (B, 1);
      while Bit > 1 loop
         Square (A, E); -- A = Fm, B = Fm+1
         Square (B, D);
         Add (E, D);
         Set (D, B);
         Mul_By_Power_Of_Two (D, 1);
         Sub (D, A);
         Mul (D, A);
         Swap (A, D);
         Swap (B, E);
         M := M * 2; -- A = Fm, B = Fm+1
         Bit := Bit / 2;
         if (N / Bit) mod 2 /= 0 then
            Set (D, B);
            Add (D, A);
            Swap (A, B);
            Swap (D, B);
            M := M + 1; -- A = Fm, B = Fm+1
        end if;
      end loop;
      return A;
   end Fibonacci;

```

Note unbounded integers, Fibonacci numbers grow very fast. If you need just bounded values simply tabulate them. See this [page](https://r-knott.surrey.ac.uk/fibonacci/fibtable.html). In practice Fibonacci numbers are computed by some modulo in Montgomery domain..

---

<div class="post-metadata">

**Author:** ![Lucretia](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/lucretia/32/17_2.png) [@Lucretia](https://forum.ada-lang.io/u/Lucretia)\
**Post date:** [December 4, 2025, 8:54pm UTC](https://forum.ada-lang.io/t/how-does-async-concurrency-work-in-ada-compared-to-other-languages/2247/14 "2025-12-04T20:54:55Z")

</div>

See [here](https://forum.ada-lang.io/t/ada-monthly-meetup-november-2025/3913/6) for info on gcc 16.

---

<div class="post-metadata">

**Author:** ![ValorZard](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/valorzard/32/623_2.png) [@ValorZard](https://forum.ada-lang.io/u/ValorZard)\
**Post date:** [December 5, 2025, 7:52am UTC](https://forum.ada-lang.io/t/how-does-async-concurrency-work-in-ada-compared-to-other-languages/2247/15 "2025-12-05T07:52:10Z")

</div>

Right so the right person to ask would be @sttaft
