1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 00:29:46 +01:00
RIOT/examples/thread_duel
AnnsAnn 237b71528c examples: Create a proper Table of Content
examples: ToC about all examples

examples: Fix whiteline issues

examples: Improve wording of Rust example

Co-authored-by: Teufelchen <9516484+Teufelchen1@users.noreply.github.com>

examples: Reduce redundant wording

Co-authored-by: Teufelchen <9516484+Teufelchen1@users.noreply.github.com>

examples: remove mention of repository

Co-authored-by: Teufelchen <9516484+Teufelchen1@users.noreply.github.com>

examples: Improve wording of coap example text

Co-authored-by: Teufelchen <9516484+Teufelchen1@users.noreply.github.com>
2024-11-12 16:17:03 +01:00
..
main.c treewide: remove THREAD_CREATE_STACKTEST from thread creation 2024-07-29 11:45:58 +02:00
Makefile examples/thread-duel: add a duelling threads example 2021-11-11 13:18:53 +01:00
Makefile.ci examples and tests: add atmega8 to relevent Makefile.ci 2023-07-11 21:22:02 +02:00
README.md examples: Create a proper Table of Content 2024-11-12 16:17:03 +01:00

Thread-Duel

This is a thread duel application to show RIOTs abilities to run multiple-threads concurrently, even if they are neither cooperative nor dividable into different scheduler priorities, by using the optional round-robin scheduler module.

Every thread will do some work (busy waiting). After the work is done it counts up by the amount of work it did and then it rests. There are different resting strategies and these have a huge influence on thread fairness and scheduling.

Resting strategies for the threads of this example are:

  • nice_wait: does nice breaks giving other threads time to use the CPU
  • bad_wait: takes breaks by busy waiting and therefore hogging the CPU
  • yield_wait: takes no explicit breaks but yields (to higher or equal priority threads)
  • no_wait: never takes a break

After completing a batch of work (and rest) a thread will print information on the work done. (Printing is done in steps to avoid flooding)

If one thread (all are same priority) follows bad_wait or no_wait strategy, scheduling without round robin will see all CPU time be hogged by that one thread (or the first one to get it).

In this example Round Robin scheduling is enabled by default, to disable compile with RR=0

Change the behaviour of the different threads by adding CFLAGS='-DTHREAD_1={<rest_strategy>,<work>}'

e.g.:

CFLAGS='-DTHREAD_1={yield_wait,3} -DTHREAD_2={bad_wait,2}' RR=0 make

Will set:

  • thread 1 to follow yield_waiting strategy and to complete 3 works in one batch after that, it will yield.
  • thread 2 will do 2 work and follow bad_wait (hog the cpu while waiting). the Round Robin scheduling is not activated.

The result will be:

  • CPU hogged by thread 2, which will only do work for 20% of the time (really bad)
  • thread 1 will have done 3 work but will never even get the chance to print that
  • thread 3 will never have done any work.