zephyr/samples/philosophers
Anas Nashif a1d7794647 samples: minor documentation tweaks
Change-Id: I9efe25dbc808c635d895ffe2893afb68f4088ad1
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-06 18:49:24 -05:00
..
src samples: put philosophers stacks in noinit section 2017-01-06 17:38:21 +00:00
Makefile samples: tests: remove obsolete KERNEL_TYPE and kernel variables 2016-11-04 15:47:25 -04:00
README.rst samples: minor documentation tweaks 2017-01-06 18:49:24 -05:00
prj.conf samples: configure philosophers with more than 32 priorities 2016-11-18 23:45:35 +00:00

README.rst

Dining Philosophers
###################

Overview
========

An implementation of a solution to the Dining Philosophers problem (a classic
multi-thread synchronization problem).  This particular implementation
demonstrates the usage of multiple preemptible and cooperative threads of
differing priorities, as well as dynamic mutexes and thread sleeping.

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:

.. code-block:: console

   $ cd samples/philosophers
   $ make qemu

Sample Output
-------------

.. code-block:: console

   Philosopher 0 [P: 3]  HOLDING ONE FORK
   Philosopher 1 [P: 2]  HOLDING ONE FORK
   Philosopher 2 [P: 1]  EATING  [ 1900 ms ]
   Philosopher 3 [P: 0]  THINKING [ 2500 ms ]
   Philosopher 4 [C:-1]  THINKING [ 2200 ms ]
   Philosopher 5 [C:-2]  THINKING [ 1700 ms ]