• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

src/18-Mar-2025-279207

CMakeLists.txtD18-Mar-2025355 118

KconfigD18-Mar-2025292 1712

README.rstD18-Mar-20251.4 KiB5640

prj.confD18-Mar-2025309 149

sample.yamlD18-Mar-2025402 2221

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