[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
Giovanni
Site Admin
Posts: 12748
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 696 times
Been thanked: 573 times
Contact:

[NEWS] Delegate threads

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

Hi,

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.

Giovanni

User avatar
RoccoMarco
Posts: 632
Joined: Wed Apr 24, 2013 4:11 pm
Location: Salerno (Italy)
Has thanked: 76 times
Been thanked: 60 times
Contact:

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.
Ciao,
RM


Return to “Development and Feedback”

Who is online

Users browsing this forum: Bing [Bot] and 5 guests