Ada Rendezvous Implemented in C with Pthreads

I've been curious about Ada 2012 ever since I read about it.1 I recently learned that Ada was originally designed for embedded systems and that piqued my interest even more. One particularly interesting Ada feature is language support for tasks (aka threads), including a built-in scheduler. The task support includes a feature for inter-task communication and synchronization called a "rendezvous". Since I had never used a language with that feature, the concept was a bit confusing at first.

After writing some Go code I realized that the Ada rendezvous was very similar to using channels to communicate between goroutines. Both Go channels and the Ada rendezvous are descendants of Tony Hoare's Communicating Sequential Processes (CSP), so there's a strong theoretical basis behind them.2

The basic idea is that a task can call a procedure provided by another task, but the code will only run after they have both reached the "rendezvous". One task has a rendezvous "entry point" which looks like a procedure (aka function). When that task "accepts" the entry point, it will sleep and wait for another task to call the procedure, or "enter" the rendezvous. If a task tries to enter the rendezvous before the accepting task is ready to accept, then the entering task will sleep until the accepting task is ready. In other words, the first task to reach the rendezvous sleeps until the other task reaches the rendezvous. When both tasks are ready, the rendezvous procedure will run with input parameters passed by the entering task and it will return values back to the entering task. Both tasks are synchronized while the rendezvous code runs, meaning they won't resume executing their task code until the rendezvous finishes. Since the two tasks only exchange data while synchronized there is no need for mutexes.

To get an even better understanding of the Ada Rendezvous, I decided to implement a subset of the functionality in C using Pthreads for the Rosetta Code project. I posted my implementation on September 9th, 2020:

https://rosettacode.org/wiki/Rendezvous#Pthreads_implementation

Footnotes:

1

My professional work is mostly embedded firmware, usually implemented in C. C is imperfect, but since it's one of the first languages I learned and the one I work with the most, it's the one I usually "think" in. Even though it is a "systems language" designed for implementing portable operating systems, I've long felt that embedded systems would be better served by a language explicitly designed for firmware and real-time embedded systems. Ada is one such language. I know bad code can be written in any language and that simply switching from one to another won't increase the quality of any project, but it is still good to consider alternative ways of tackling a problem and to learn from the collective experience of other software engineers. Reading about Ada makes me a better C programmer.

2

Embedded System Design by Peter Marwedel briefly discusses the connection between CSP and the Ada rendezvous on page 111. The book is a wide ranging survey of embedded systems hardware, software, theory, techniques, and algorithms. The fourth edition is open-access and the PDF is free to download, though I'm happy to have purchased a print copy.

© Copyright 2023, Remington Furman

blog@remcycles.net

@remcycles@subdued.social