README.rst
1.. zephyr:code-sample:: posix-philosophers
2 :name: POSIX Philosophers
3
4 Implement a solution to the Dining Philosophers problem using the POSIX API.
5
6Overview
7********
8
9This sample implements Zephyr's :zephyr:code-sample:`dining-philosophers` sample using the
10:ref:`POSIX API <posix_support>`. The source code for this sample can be found under
11:file:`samples/posix/philosophers`.
12
13Building and Running
14********************
15
16This project outputs to the console. It can be built and executed on QEMU as follows:
17
18.. zephyr-app-commands::
19 :zephyr-app: samples/posix/philosophers
20 :host-os: unix
21 :board: qemu_riscv64
22 :goals: run
23 :compact:
24
25Sample Output
26=============
27
28.. code-block:: console
29
30 Philosopher 0 [P: 3] HOLDING ONE FORK
31 Philosopher 1 [P: 2] HOLDING ONE FORK
32 Philosopher 2 [P: 1] EATING [ 1900 ms ]
33 Philosopher 3 [P: 0] THINKING [ 2500 ms ]
34 Philosopher 4 [C:-1] THINKING [ 2200 ms ]
35 Philosopher 5 [C:-2] THINKING [ 1700 ms ]
36
37Exit QEMU by pressing :kbd:`CTRL+A` :kbd:`x`.
38
39Debugging
40*********
41
42Like the original philosophers sample, the POSIX variant also enables
43:kconfig:option:`CONFIG_DEBUG_THREAD_INFO` by default.
44
45.. zephyr-app-commands::
46 :zephyr-app: samples/philosophers
47 :host-os: unix
48 :board: <board_name>
49 :goals: debug
50 :compact:
51
52Additional Information
53**********************
54
55For additional information, please refer to the :zephyr:code-sample:`dining-philosophers` sample.
56