[NEWS] Delegate threads

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
User avatar
Site Admin
Posts: 14462
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1078 times
Been thanked: 922 times

[NEWS] Delegate threads

Postby Giovanni » Sun Nov 17, 2019 11:33 am


I just committed a prototype of this new mechanism "Delegate Threads" in the OSLIB, in brief it is built on top of messages and allows to invoke C functions in the context of another thread.

Imagine encapsulating a whole non-thread-safe subsystem inside a thread, for example a graphic library or a file system. Other threads will be able to call functions of the subsystem from remote without having to implement an ad-hoc messages protocol or implementing mutual exclusion, calls are implicitly synchronized.

The delegate thread has to implement something like this:

Code: Select all

/* Messages dispatcher loop.*/
while (true) {
  chDelegateDispatchTimeout(TIME_INFINITE) {

Other threads will be able to call functions inside the delegate using:

Code: Select all

ret = chDelegateCallDirect2(tp, remote_func, p1, p2);

It is also possible to hide details by creating convenient proxy functions like this:

Code: Select all

static inline int my_remote_func(int p1, int p2) {

  return (int)chDelegateCallDirect2(tp, remote_func, p1, p2):

The general idea is to create wrappers for common external subsystems using an unified remote call layer. I am thinking to FatFS and LittlevGL. The mechanism has an overhead of two thread-to-thread context switch operations, which is very efficient in ChibiOS.


User avatar
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Location: Munich (Germany)
Has thanked: 83 times
Been thanked: 67 times

Re: [NEWS] Delegate threads

Postby RoccoMarco » Mon Nov 18, 2019 9:52 am

It sounds a powerful mechanism to deal with complex systems. With this, it is possible to easily create centralized handlers and there are plenty of use cases for this scenario.

Posts: 18
Joined: Mon Sep 13, 2021 6:46 pm
Has thanked: 2 times
Been thanked: 1 time

Re: [NEWS] Delegate threads

Postby TKorho » Thu Feb 10, 2022 12:05 pm

Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 5 guests