Threads and channelsΒΆ
A thread is the basic execution entity. A scheduler controls the execution of threads.
A simple thread that waits to be resumed by another thread.
#include "simba.h"
void *my_thread_main(void *arg_p)
{
UNUSED(arg_p);
while (1) {
thrd_suspend(NULL);
std_printf(FSTR("Thread resumed.\r\n"));
}
return (NULL);
}
Threads usually communicates over channels. There are two kinds of channels; queue and event. Both implementing the same abstract channel interface (see src/kernel/chan.h). This abstraction makes channel very powerful as a synchronization primitive. They can be seen as limited functionality file descriptors in linux.
The most common channel is the queue. It can be either synchronous or semi-asynchronous. In the synchronous version the writing thread will block until all written data has been read by the reader. In the semi-asynchronous version the writer writes to a buffer within the queue, and only blocks all data does not fit in the buffer. The buffer size is selected by the application.