[riot-users] Thread Yielding problem

Robin robin at chilio.net
Thu Jul 25 17:05:21 CEST 2019


Hi,

On 25.07.19 16:41, Burak Karaduman wrote:
>   thread_create(rcv_thread_stack, sizeof(rcv_thread_stack),
>                   THREAD_PRIORITY_MAIN - 1, THREAD_CREATE_STACKTEST,
>                   rcv_thread, NULL, "rcv_thread");
>
After the creating of this thread the main thread itself yields and the 
new thread is scheduled due to its higher priority (less means higher 
priority like with Unix nice values). When the new Thread yields it 
always get scheduled again, since there is no thread with an higher 
priority.

>
>     thread_create(ccc_thread_stack, sizeof(ccc_thread_stack),
>                   THREAD_PRIORITY_MAIN - 1, THREAD_CREATE_STACKTEST,
>                   ccc_thread, NULL, "ccc_thread");
>
This thread is never created since the main Thread is not scheduled again.


You can use the option "THREAD_CREATE_WOUT_YIELD" to prevent the main 
thread from yielding. This would result in both threads are started and 
afterwards scheduled in an alternating way (assuming you yield in both 
threads), but would prevent you main loop from getting scheduled. If you 
need your main thread to run also, you can use the same priorities for 
all three threads.


Please not that the documentation states "Avoid assigning the same 
priority to two or more threads.". But i have no clue for what reason.


Regards,

Robin



More information about the users mailing list