{{htmlmetatags>metatag-robots=()
metatag-title=(Coordinate the protothreads | Multithreading on retrocomputers)
metatag-keywords=(Multithreading,Commodore 64,Commodore VIC20,Atari,Commodore128,MIDRES Library,6502,6510)
metatag-description=(How to implement fast and efficient multithreading on computers with limited resources.)
metatag-media-og:image=(:mt6502.png)
metatag-og:title=(Coordinate the protothreads | Multithreading on retrocomputers)
metatag-og:description=(How to implement fast and efficient multithreading on computers with limited resources.)
}}
====== Multithreading on retrocomputers ======
===== COORDINATE THE PROTOTHREADS =====
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:
- at the end of the thread;
- when it explicitly cedes control;
- when passing into the waiting state.
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 [[:mt6502:blocking|BLOCKING AND NON-BLOCKING FUNCTIONS]].