POSIX Philosophers

Overview

This sample implements Zephyr’s Dining Philosophers Sample using the POSIX API. The source code for this sample can be found under samples/posix/philosophers.

Building and Running

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

west build -b qemu_riscv64 samples/posix/philosophers
west build -t run

Sample Output

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 ]

Exit QEMU by pressing CTRL+A x.

Debugging

Like the original philosophers sample, the POSIX variant also enables CONFIG_DEBUG_THREAD_INFO by default.

west build -b <board_name> samples/philosophers
west debug

Additional Information

For additional information, please refer to the Dining Philosophers Sample.