2021-04-15 14:59:50 +02:00
Thread-Duel
============
2021-10-27 14:10:19 +02:00
This is a thread duel application to show RIOTs abilities to run multiple-threads
2024-11-06 13:29:36 +01:00
concurrently, even if they are neither cooperative nor dividable into different scheduler priorities, by using the optional round-robin scheduler module.
2021-04-15 14:59:50 +02:00
2021-10-27 14:10:19 +02:00
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.
2021-04-15 14:59:50 +02:00
There are different resting strategies and these have a huge
influence on thread fairness and scheduling.
2021-10-27 14:10:19 +02:00
Resting strategies for the threads of this example are:
2021-04-15 14:59:50 +02:00
- `nice_wait` : does nice breaks giving other threads time to use the CPU
2021-10-27 14:10:19 +02:00
- `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
2021-04-15 14:59:50 +02:00
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)
2021-10-27 14:10:19 +02:00
If one thread (all are same priority) follows `bad_wait` or `no_wait` strategy,
2021-04-15 14:59:50 +02:00
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`
2021-10-27 14:10:19 +02:00
Change the behaviour of the different threads by adding
`CFLAGS='-DTHREAD_1={<rest_strategy>,<work>}'`
2021-04-15 14:59:50 +02:00
e.g.:
```
CFLAGS='-DTHREAD_1={yield_wait,3} -DTHREAD_2={bad_wait,2}' RR=0 make
```
2021-10-27 14:10:19 +02:00
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).
2021-04-15 14:59:50 +02:00
the Round Robin scheduling is not activated.
2021-10-27 14:10:19 +02:00
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.