zephyr/samples/portability/cmsis_rtos_v2/philosophers
Andrew Boie feab37096b libc: fix CONFIG_STDOUT_CONSOLE semantics
The intent of this Kconfig is to allow libc stdout
functions like printf() to send their output to the
active console driver instead of discarding it.

This somehow evolved into preferring to use
printf() instead of printk() for all test case output
if enabled. Libc printf() implementation for both
minimal libc and newlib use considerably more stack
space than printk(), with nothing gained by using
them.

Remove all instances where we are conditionally
sending test case output based on this config, enable
it by default, and adjust a few tests that disabled
this because they were blowing stack.

printk() and vprintk() now work as expected for
unit_testing targets, they are just wrappers for
host printf().

Fixes: #13701

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-26 08:00:33 -06:00
..
src libc: fix CONFIG_STDOUT_CONSOLE semantics 2019-02-26 08:00:33 -06:00
CMakeLists.txt
README.rst
prj.conf libc: fix CONFIG_STDOUT_CONSOLE semantics 2019-02-26 08:00:33 -06:00
sample.yaml samples/portability/cmsis_rtos_v2/philosophers: Exclude qemu_x86_64 2019-02-08 14:49:39 -05:00

README.rst

.. _cmsis_rtos_v2-sample:

Dining Philosophers (CMSI RTOS V2 APIs)
#######################################

Overview
********
This sample implements a solution to the `Dining Philosophers problem
<https://en.wikipedia.org/wiki/Dining_philosophers_problem>`_ (a classic
multi-thread synchronization problem) using CMSIS RTOS V2 APIs.  This particular
implementation demonstrates the usage of multiple preemptible and cooperative
threads of differing priorities, as well as mutex/semaphore and thread sleeping
which uses CMSIS RTOS V2 API implementation in Zephyr.

The philosopher always tries to get the lowest fork first (f1 then f2).  When
done, he will give back the forks in the reverse order (f2 then f1).  If he
gets two forks, he is EATING.  Otherwise, he is THINKING. Transitional states
are shown as well, such as STARVING when the philosopher is hungry but the
forks are not available, and HOLDING ONE FORK when a philosopher is waiting
for the second fork to be available.

Each Philosopher will randomly alternate between the EATING and THINKING state.


Building and Running
********************

This project outputs to the console.  It can be built and executed
on QEMU as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/philosophers
   :host-os: unix
   :board: qemu_x86
   :goals: run
   :compact:

Sample Output
=============

.. code-block:: console

    Philosopher 0 [P: 8]    HOLDING ONE FORK
    Philosopher 1 [P: 9]    HOLDING ONE FORK
    Philosopher 2 [P: 10]   EATING  [  575 ms ]
    Philosopher 3 [P: 11]  THINKING [  225 ms ]
    Philosopher 4 [P: 12]  THINKING [  425 ms ]
    Philosopher 5 [P: 13]  THINKING [  325 ms ]

    Demo Description
    ----------------
    An implementation of a solution to the Dining Philosophers
    problem (a classic multi-thread synchronization problem) using
    CMSIS RTOS V2 APIs. This particular implementation demonstrates the
    usage of multiple preemptible threads of differing
    priorities, as well as semaphores and thread sleeping.