samples/subsys/portability/cmsis_rtos_v2/philosophers/README.html · samples/subsys/portability/cmsis_rtos_v2/philosophers/README.rst 공식 원문 ↗

Zephyr 3.7.0 · Samples · Portability · CMSIS-RTOS V2

Dining Philosophers(CMSIS-RTOS V2)

Fork 획득 순서와 HOLDING ONE FORK를 포함한 thread 상태 전이를 관찰합니다.

Official pathsamples/subsys/portability/cmsis_rtos_v2/philosophers/README.html
Source filesamples/subsys/portability/cmsis_rtos_v2/philosophers/README.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

본문 기준: Zephyr 3.7.0 LTS3 · 이후 유지보수 패치는 별도입니다.

Part 1

요약·해설

Preemptible·cooperative thread, fork ordering, EATING·THINKING·HOLDING 상태를 설명합니다.

API

CMSIS-RTOS V2

Sync

Mutex · Semaphore

States

Holding · Thinking · Eating

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 56ABE0232DB80B0B3F43B661D79489DE3DF93F797F2BE523CFEB83B6A3080769
.. zephyr:code-sample:: cmsis-rtos-v2
   :name: Dining Philosophers (CMSIS RTOS V2 APIs)

   Implement a solution to the Dining Philosophers problem using CMSIS RTOS V2.

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 V2 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 V2 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 [P: 8]    HOLDING ONE FORK
    Philosopher 1 [P: 9]    HOLDING ONE FORK
    Philosopher 2 [P: 10]   EATING  [  575 ms ]
    Philosopher 3 [P: 11]  THINKING [  225 ms ]
    Philosopher 4 [P: 12]  THINKING [  425 ms ]
    Philosopher 5 [P: 13]  THINKING [  325 ms ]

    Demo Description
    ----------------
    An implementation of a solution to the Dining Philosophers
    problem (a classic multi-thread synchronization problem) using
    CMSIS RTOS V2 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 V2 API로 해결하는 sample입니다. Zephyr의 CMSIS-RTOS V2 구현을 통해 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 V2 API의 thread priority, semaphore와 sleep을 시험한다는 점을 다시 설명합니다.

Philosopher 0 [P: 8]    HOLDING ONE FORK
Philosopher 1 [P: 9]    HOLDING ONE FORK
Philosopher 2 [P: 10]   EATING  [  575 ms ]
Philosopher 3 [P: 11]  THINKING [  225 ms ]
Philosopher 4 [P: 12]  THINKING [  425 ms ]
Philosopher 5 [P: 13]  THINKING [  325 ms ]

Demo Description
----------------
An implementation of a solution to the Dining Philosophers
problem (a classic multi-thread synchronization problem) using
CMSIS RTOS V2 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

출처

영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.