Part 1
요약·해설
Preemptible·cooperative thread, fork ordering, EATING·THINKING·STARVING 상태를 설명합니다.
CMSIS-RTOS V1
Mutex · Semaphore
Thinking · Eating · Starving
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
87582C077428C6A09EC1CC856784B48FC52755250D50305E780A91249F89DF89
.. zephyr:code-sample:: cmsis-rtos-v1
:name: Dining Philosophers (CMSIS RTOS V1 APIs)
Implement a solution to the Dining Philosophers problem using CMSIS RTOS V1.
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 V1 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 V1 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 [C:-2] THINKING [ 500 ms ]
Philosopher 1 [C:-1] THINKING [ 375 ms ]
Philosopher 2 [P: 0] THINKING [ 575 ms ]
Philosopher 3 [P: 1] EATING [ 525 ms ]
Philosopher 4 [P: 2] THINKING [ 800 ms ]
Philosopher 5 [P: 3] EATING [ 625 ms ]
Demo Description
----------------
An implementation of a solution to the Dining Philosophers
problem (a classic multi-thread synchronization problem) using
CMSIS RTOS V1 APIs. This particular implementation demonstrates the
usage of multiple preemptible threads of differing
priorities, as well as semaphores and thread sleeping.
Exit QEMU by pressing :kbd:`CTRL+A` :kbd:`x`.
Part 3
한국어 전문 번역
개요
Classic multi-thread synchronization 문제인 Dining Philosophers를 CMSIS-RTOS V1 API로 해결하는 sample입니다. Zephyr의 CMSIS-RTOS V1 구현을 통해 priority가 서로 다른 여러 preemptible·cooperative thread, mutex/semaphore와 thread sleep을 사용합니다.
각 philosopher는 항상 번호가 낮은 fork를 먼저 얻습니다. 즉 f1 다음 f2 순서로 잡고, 식사가 끝나면 반대 순서인 f2 다음 f1로 돌려줍니다.
Fork 두 개를 모두 얻으면 EATING, 그렇지 않으면 THINKING 상태입니다. 배고프지만 fork를 얻지 못하면 STARVING, 첫 fork만 들고 두 번째를 기다리면 HOLDING ONE FORK라는 전이 상태도 표시합니다. 각 philosopher는 임의 시간 간격으로 EATING과 THINKING을 번갈아 수행합니다.
빌드 및 실행
Project는 console로 상태를 출력하며 다음 공식 command로 qemu_x86에서 build하고 실행합니다.
west build -b qemu_x86 samples/philosophers
west build -t run
샘플 출력
각 행은 philosopher 번호, scheduler class·priority, 현재 상태와 상태 유지 시간을 보여 줍니다. 마지막 Demo Description은 이 실행이 CMSIS-RTOS V1 API의 thread priority, semaphore와 sleep을 시험한다는 점을 다시 설명합니다.
Philosopher 0 [C:-2] THINKING [ 500 ms ]
Philosopher 1 [C:-1] THINKING [ 375 ms ]
Philosopher 2 [P: 0] THINKING [ 575 ms ]
Philosopher 3 [P: 1] EATING [ 525 ms ]
Philosopher 4 [P: 2] THINKING [ 800 ms ]
Philosopher 5 [P: 3] EATING [ 625 ms ]
Demo Description
----------------
An implementation of a solution to the Dining Philosophers
problem (a classic multi-thread synchronization problem) using
CMSIS RTOS V1 APIs. This particular implementation demonstrates the
usage of multiple preemptible threads of differing
priorities, as well as semaphores and thread sleeping.
QEMU를 종료하려면 CTRL+A를 누른 다음 x를 입력합니다.
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.