Protothreads are threads that run in a cooperative multithreading context. Protothreads voluntarily relinquish control once the current operation is over. More precisely, the scheduler passes control to another thread only in three cases:
The first case occurs when the function ends, arriving at the MR_PTI_END
annotation. The second case is triggered by the MR_PTI_YIELD
call, which we have already in the previous chapter.
The third, more interesting case occurs when one of the wait functions is called:
MR_PTI_WAIT_UNTIL(condition)
waits until condition becomes true;MR_PTI_WAIT_WHILE(condition)
waits while condition is true;MR_PTI_WAIT_THREAD(thread)
waits for the end of thread execution.These functions are useful as they allow to implement more or less complex forms of cooperation and / or synchronism.
Move to BLOCKING AND NON-BLOCKING FUNCTIONS.