1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-28 22:49:47 +01:00
RIOT/examples/thread_duel
Hugues Larrive 3c465836f2 examples and tests: add atmega8 to relevent Makefile.ci
using dist/tools/insufficient_memory/add_insufficient_memory_board.sh
2023-07-11 21:22:02 +02:00
..
main.c examples/thread-duel: improve duelling threads example 2021-12-08 13:13:48 +01: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/thread-duel: improve duelling threads example 2021-12-08 13:13:48 +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.