feat: add lab-rv32i-freertos-mutex card
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
# K11 — Mutex, LockGuard and priority inheritance
|
||||
|
||||
## Position
|
||||
|
||||
- Series: FreeRTOS C++
|
||||
- Lesson: L10, card K11
|
||||
- Duration: 30 minutes
|
||||
- Actors: LOW=1, MEDIUM=2, HIGH=3, coordinator=4
|
||||
- Storage: static mutex control and static task stacks
|
||||
|
||||
## Outcome
|
||||
|
||||
The student distinguishes mutex ownership from semaphore signaling, repairs
|
||||
early returns with `LockGuard`, and explains every state/priority transition in
|
||||
a measured priority-inheritance schedule.
|
||||
|
||||
## Lesson plan
|
||||
|
||||
| Time | Mode | Evidence |
|
||||
| --- | --- | --- |
|
||||
| 0–5 | ownership | owner-only give; ordinary mutex non-recursive |
|
||||
| 5–10 | LockGuard | three returns each give exactly once |
|
||||
| 10–15 | setup | LOW takes; HIGH attempts; MEDIUM ready |
|
||||
| 15–20 | inheritance | HIGH blocked; LOW priority rises 1→3 |
|
||||
| 20–25 | release | MEDIUM has not run; HIGH acquires next |
|
||||
| 25–30 | restore | LOW returns to 1; protected counter is 11 |
|
||||
|
||||
## Acceptance
|
||||
|
||||
- mutex handle equals caller static control and heap delta is zero;
|
||||
- LOW owns at first checkpoint and HIGH owns after handoff;
|
||||
- HIGH is blocked while waiting;
|
||||
- LOW priority is exactly 1, then 3, then 1;
|
||||
- MEDIUM does not run before LOW release;
|
||||
- event order proves inherited LOW precedes MEDIUM;
|
||||
- guard restores on every host early-return path;
|
||||
- ordinary recursive attempt fails;
|
||||
- target exits with PASS and shared counter 11.
|
||||
|
||||
## Main traps
|
||||
|
||||
1. A binary semaphore is not an ownership mutex and has no inheritance.
|
||||
2. Ordinary mutex recursion deadlocks/fails; use a recursive type deliberately.
|
||||
3. Only the owner may unlock.
|
||||
4. Mutex APIs are not ISR APIs.
|
||||
5. Inheritance is temporary and bounded by the held mutex lifetime.
|
||||
@@ -0,0 +1,344 @@
|
||||
% Generated from json/card_source.json by tools/render_card.py.
|
||||
% Do not edit manually; update the JSON and regenerate.
|
||||
|
||||
\documentclass[12pt,a4paper]{article}
|
||||
|
||||
\usepackage[T1]{fontenc}
|
||||
\usepackage{lmodern}
|
||||
\usepackage[utf8]{inputenc}
|
||||
\usepackage[polish]{babel}
|
||||
\usepackage{csquotes}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{amssymb}
|
||||
\usepackage{xcolor}
|
||||
\usepackage[a4paper,left=2.15cm,right=2.15cm,top=0.5cm,bottom=0.5cm,headheight=24mm,headsep=3mm,includehead]{geometry}
|
||||
\usepackage{eso-pic}
|
||||
\usepackage{marginnote}
|
||||
\usepackage{array}
|
||||
\usepackage{tabularx}
|
||||
\usepackage{graphicx}
|
||||
\usepackage{pdflscape}
|
||||
\usepackage{float}
|
||||
\usepackage{silence}
|
||||
\WarningFilter{soulutf8}{This package is obsolete}
|
||||
\usepackage{pdfcomment}
|
||||
\usepackage{enumitem}
|
||||
\usepackage{needspace}
|
||||
\usepackage{fancyhdr}
|
||||
\usepackage{lastpage}
|
||||
\usepackage{microtype}
|
||||
\usepackage[most]{tcolorbox}
|
||||
\usepackage{qrcode}
|
||||
\IfFileExists{references.bib}{%
|
||||
\usepackage[backend=biber,style=numeric,sorting=none]{biblatex}%
|
||||
\addbibresource{references.bib}%
|
||||
}{}
|
||||
|
||||
\hypersetup{hidelinks}
|
||||
|
||||
\IfFileExists{build-meta.tex}{%
|
||||
\input{build-meta.tex}%
|
||||
}{%
|
||||
\newcommand{\BuildCommit}{lokalna}%
|
||||
}
|
||||
|
||||
\newcommand{\DocumentAuthor}{M. Pabiszczak}
|
||||
\newcommand{\DocumentYear}{2026}
|
||||
\newcommand{\CardSeries}{freertos-cpp}
|
||||
\newcommand{\CardNumber}{11}
|
||||
\newcommand{\CardCount}{16}
|
||||
\newcommand{\CardSlug}{mutex}
|
||||
\newcommand{\CardVersion}{v00.01}
|
||||
\newcommand{\DocumentUUID}{34d7ad61-6b03-4922-8e58-b8b98316e5f7}
|
||||
|
||||
\newcommand{\EmptyCheck}{\(\square\)}
|
||||
\newcommand{\EscAnswerLines}[1][3]{\par\noindent\dotfill\par\noindent\dotfill\par\noindent\dotfill}
|
||||
\newcommand{\EscWriteRow}[1][2.8em]{\rule{0pt}{#1}}
|
||||
\setlength{\parindent}{0pt}
|
||||
\setlength{\parskip}{0.45em}
|
||||
\setlength{\headheight}{24mm}
|
||||
\setlength{\headsep}{3mm}
|
||||
\setlength{\footskip}{8mm}
|
||||
\setlength{\marginparwidth}{1.5cm}
|
||||
\setlength{\marginparsep}{0.25cm}
|
||||
\renewcommand{\arraystretch}{1.22}
|
||||
% Margin separator lines disabled for layout trial.
|
||||
|
||||
\newcommand{\ESCPageResourceHeader}{%
|
||||
\begingroup%
|
||||
\setlength{\parskip}{0pt}%
|
||||
\setlength{\fboxsep}{0pt}%
|
||||
\setlength{\fboxrule}{0.35pt}%
|
||||
\setlength{\arrayrulewidth}{0.35pt}%
|
||||
\noindent\fbox{%
|
||||
\begin{minipage}[c][23.5mm][c]{\dimexpr\textwidth-2\fboxrule\relax}%
|
||||
\begin{minipage}[c][23mm][c]{\dimexpr\linewidth-24mm-0.35pt\relax}%
|
||||
\setlength{\tabcolsep}{0pt}%
|
||||
\renewcommand{\arraystretch}{0}%
|
||||
\begin{tabularx}{\linewidth}{@{}p{\dimexpr0.50000000\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.15126050\linewidth-\arrayrulewidth\relax}|X@{}}%
|
||||
\parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries TITLE}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{7.7}{7.9}\selectfont\ttfamily\bfseries Mutex, LockGuard and Priority Inheritance}\hspace{0.45mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries VER.}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{6.6}{6.8}\selectfont\ttfamily\bfseries v00.01}\hspace{0.45mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries DATETIME}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{6.4}{6.6}\selectfont\ttfamily\bfseries 2026-07-19T00:00:00+02:00}\hspace{0.45mm}}\par} \\%
|
||||
\end{tabularx}%
|
||||
\par\nointerlineskip%
|
||||
\hrule height0.35pt%
|
||||
\nointerlineskip%
|
||||
\begin{tabularx}{\linewidth}{@{}p{\dimexpr0.50000000\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.25210084\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.14285714\linewidth-\arrayrulewidth\relax}|X@{}}%
|
||||
\parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries PROJECT}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{7.7}{7.9}\selectfont\ttfamily\bfseries Freestanding C++ nad FreeRTOS}\hspace{0.45mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries SERIES}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{6.4}{6.6}\selectfont\ttfamily\bfseries FreeRTOS C++}\hspace{0.45mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries CARD}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{6.4}{6.6}\selectfont\ttfamily\bfseries 11/16}\hspace{0.45mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries SHEET}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{6.4}{6.6}\selectfont\ttfamily\bfseries \thepage/\pageref{LastPage}}\hspace{0.45mm}}\par} \\%
|
||||
\end{tabularx}%
|
||||
\par\nointerlineskip%
|
||||
\hrule height0.35pt%
|
||||
\nointerlineskip%
|
||||
\begin{tabularx}{\linewidth}{@{}p{\dimexpr0.05882353\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.05042017\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.14705882\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.09243697\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.07563025\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.07563025\linewidth-\arrayrulewidth\relax}|X@{}}%
|
||||
\parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.15mm}{\fontsize{2.85}{3}\selectfont\ttfamily\bfseries SUBJ.}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{4.45}{4.65}\selectfont\ttfamily\bfseries Inf.}\hspace{0.15mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.15mm}{\fontsize{2.85}{3}\selectfont\ttfamily\bfseries PROG.}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{4.45}{4.65}\selectfont\ttfamily\bfseries —}\hspace{0.15mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.15mm}{\fontsize{2.85}{3}\selectfont\ttfamily\bfseries CORE}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{4.45}{4.65}\selectfont\ttfamily\bfseries —}\hspace{0.15mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.15mm}{\fontsize{2.85}{3}\selectfont\ttfamily\bfseries SCOPE}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{4.45}{4.65}\selectfont\ttfamily\bfseries —}\hspace{0.15mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.15mm}{\fontsize{2.85}{3}\selectfont\ttfamily\bfseries LEVEL}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{4.45}{4.65}\selectfont\ttfamily\bfseries —}\hspace{0.15mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.15mm}{\fontsize{2.85}{3}\selectfont\ttfamily\bfseries POS.}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{4.45}{4.65}\selectfont\ttfamily\bfseries —}\hspace{0.15mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hbox to\linewidth{\hspace{0.35mm}{\fontsize{3.4}{3.75}\selectfont\ttfamily\bfseries GITEA UUID}\hfill{\fontsize{3.4}{3.75}\selectfont\ttfamily 34d7ad61-6b03-4922-8e58-b8b98316e5f7}\hspace{0.35mm}}\par\nointerlineskip\hbox to\linewidth{\hspace{0.35mm}{\fontsize{3.4}{3.75}\selectfont\ttfamily\bfseries CARD UUID} {\fontsize{3.4}{3.75}\selectfont\ttfamily 34d7ad61-6b03-4922-8e58-b8b98316e5f7}\hfill{\fontsize{3.4}{3.75}\selectfont\ttfamily\bfseries AUTHOR M. Pabiszczak}\hspace{0.35mm}}} \\%
|
||||
\end{tabularx}%
|
||||
\par\nointerlineskip%
|
||||
\hrule height0.35pt%
|
||||
\nointerlineskip%
|
||||
\begin{tabularx}{\linewidth}{@{}X@{}}%
|
||||
\parbox[c][3.46276mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{4.5}{4.85}\selectfont\ttfamily\bfseries GITEA} {\fontsize{4.5}{4.85}\selectfont\ttfamily\href{https://zsl-gitea.mpabi.pl/edu-freertos-cpp/lab-rv32i-freertos-mutex}{\nolinkurl{https://zsl-gitea.mpabi.pl/edu-freertos-cpp/lab-rv32i-freertos-mutex}}}} \\%
|
||||
\end{tabularx}%
|
||||
\par\nointerlineskip%
|
||||
\hrule height0.35pt%
|
||||
\nointerlineskip%
|
||||
\begin{tabularx}{\linewidth}{@{}X@{}}%
|
||||
\parbox[c][3.46276mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{4.5}{4.85}\selectfont\ttfamily\bfseries HTML} {\fontsize{4.5}{4.85}\selectfont\ttfamily\href{}{\nolinkurl{}}}} \\%
|
||||
\end{tabularx}%
|
||||
\end{minipage}%
|
||||
\vrule width0.35pt%
|
||||
\begin{minipage}[c][23mm][c]{24mm}\centering%
|
||||
{\tiny QR wyłączony}%
|
||||
\end{minipage}%
|
||||
\end{minipage}%
|
||||
}%
|
||||
\endgroup%
|
||||
}
|
||||
|
||||
\pagestyle{fancy}
|
||||
\fancyhf{}
|
||||
\fancyhead[C]{\ESCPageResourceHeader}
|
||||
\renewcommand{\headrulewidth}{0pt}
|
||||
\renewcommand{\footrulewidth}{0pt}
|
||||
|
||||
\newcommand{\ESCMarginTag}[4]{%
|
||||
\hspace*{#1}\textcolor{#2}{#3~#4}%
|
||||
}
|
||||
\newcommand{\ESCSectionBlockStart}{%
|
||||
\Needspace{8\baselineskip}%
|
||||
\par\vspace{0.35em}%
|
||||
\noindent\textcolor{black!28}{\rule{\textwidth}{0.35pt}}%
|
||||
\par\vspace{0.15em}%
|
||||
}
|
||||
\newcommand{\ESCSectionBlockEnd}{%
|
||||
\par\vspace{0.25em}%
|
||||
\noindent\textcolor{black!18}{\rule{\textwidth}{0.25pt}}%
|
||||
\par\vspace{0.45em}%
|
||||
}
|
||||
\newcommand{\ESCTinyStepSeparator}{%
|
||||
\par\vspace{0.10em}%
|
||||
\noindent{\color{black!18}\leaders\hbox{\rule{0.60em}{0.22pt}\hspace{0.38em}}\hfill\kern0pt}%
|
||||
\par\vspace{0.10em}%
|
||||
}
|
||||
\newtcolorbox{ESCTaskFrame}[1]{enhanced,breakable,arc=0pt,boxrule=0.35pt,colback=white,colframe=black,boxsep=0pt,left=1.4mm,right=1.4mm,top=0.8mm,bottom=0.8mm,colbacktitle=black!7,coltitle=black,title={\ttfamily\bfseries TASK\quad #1}}
|
||||
\newtcolorbox{ESCBlockFrame}[1]{enhanced,breakable,arc=0pt,boxrule=0.35pt,colback=white,colframe=black!55,boxsep=0pt,left=1.0mm,right=1.0mm,top=0.6mm,bottom=0.6mm,colbacktitle=black!4,coltitle=black,title={\ttfamily\bfseries BLOCK\quad #1}}
|
||||
\newtcolorbox{ESCStepFrame}[1]{enhanced,breakable,arc=0pt,boxrule=0.35pt,colback=white,colframe=black!28,boxsep=0pt,left=0.8mm,right=0.8mm,top=0.45mm,bottom=0.45mm,colbacktitle=black!2,coltitle=black,title={\ttfamily STEP\quad #1}}
|
||||
\newtcolorbox{ESCConclusionFrame}{enhanced,breakable,arc=0pt,boxrule=0.45pt,colback=blue!2,colframe=blue!45!black,boxsep=0pt,left=1.2mm,right=1.2mm,top=0.7mm,bottom=0.7mm,colbacktitle=blue!7,coltitle=black,title={\ttfamily\bfseries WNIOSEK}}
|
||||
|
||||
\newcommand{\ESCLearningTreeWidget}{%
|
||||
\reversemarginpar
|
||||
\marginnote[%
|
||||
\begin{minipage}{\marginparwidth}%
|
||||
\raggedright
|
||||
{\fontsize{3.55}{3.95}\selectfont\ttfamily
|
||||
\begin{minipage}[t]{\marginparwidth}%
|
||||
\raggedright
|
||||
{\bfseries\textcolor{black!65}{TECH}\par}%
|
||||
\vspace{0.08em}%
|
||||
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
|
||||
\hspace*{0.28em}\textcolor{orange!85!black}{EK~LOCAL~RTOS.MUTEX}\textcolor{black!48}{\pdftooltip[width=\textwidth]{.01}{Mierzy priority inheritance, owner i harmonogram trzech tasków.}}\par%
|
||||
\hspace*{0.54em}\textcolor{blue!70!black}{KW~LOCAL~RTOS.MUTEX}\textcolor{black!48}{\pdftooltip[width=\textwidth]{.01}{Pokazuje HIGH Blocked, LOW 1-3-1, MEDIUM after release i counter 11.}}\par%
|
||||
\end{minipage}%
|
||||
}%
|
||||
\end{minipage}%
|
||||
]{}
|
||||
\normalmarginpar
|
||||
|
||||
\marginnote{%
|
||||
\begin{minipage}{\marginparwidth}%
|
||||
\raggedright
|
||||
{\fontsize{3.55}{3.95}\selectfont\ttfamily
|
||||
\hspace*{0.06cm}%
|
||||
\begin{minipage}[t]{\dimexpr\marginparwidth-0.06cm\relax}%
|
||||
\raggedright
|
||||
{\bfseries\textcolor{black!65}{OG}\par}%
|
||||
\vspace{0.08em}%
|
||||
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
|
||||
\hspace*{0.28em}\textcolor{green!50!black}{EN~LOCAL~EN~OOP.RAII}\textcolor{black!48}{\pdftooltip[width=\textwidth]{.04}{Analizuje ownership, scoped release i invalid recursive use.}}\par%
|
||||
\hspace*{0.54em}\textcolor{blue!70!black}{KW~LOCAL~KW~OOP.RAII}\textcolor{black!48}{\pdftooltip[width=\textwidth]{.04}{Dowodzi jednego give na każdej ścieżce i właściwych granic API.}}\par%
|
||||
\end{minipage}%
|
||||
}%
|
||||
\end{minipage}%
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
\begin{document}
|
||||
\sloppy
|
||||
|
||||
\vspace{1.0em}
|
||||
\noindent{\Large\bfseries Cel karty}\par
|
||||
\vspace{0.35em}
|
||||
Uczeń odróżnia mutex od semaphore, balansuje owner-only unlock przez LockGuard i wyjaśnia zmierzoną sekwencję priority inheritance LOW 1-3-1.
|
||||
|
||||
\vspace{0.8em}
|
||||
\noindent\textcolor{black!25}{\rule{\textwidth}{0.35pt}}
|
||||
\vspace{0.7em}
|
||||
\noindent{\Large\bfseries Zakres karty}\par
|
||||
\vspace{0.35em}
|
||||
Ordinary mutex jest task-context, non-recursive i zwalniany przez ownera. Guard nie naprawia deadlocku, ISR use ani zbyt długiej sekcji.
|
||||
|
||||
\vspace{0.8em}
|
||||
\noindent\textcolor{black!25}{\rule{\textwidth}{0.35pt}}
|
||||
|
||||
\clearpage
|
||||
|
||||
\ESCSectionBlockStart
|
||||
\section{Ownership i LockGuard}
|
||||
\reversemarginpar
|
||||
\marginnote[%
|
||||
\begin{minipage}{\marginparwidth}%
|
||||
\raggedright
|
||||
{\fontsize{3.55}{3.95}\selectfont\ttfamily
|
||||
\begin{minipage}[t]{\marginparwidth}%
|
||||
\raggedright
|
||||
{\bfseries\textcolor{black!65}{TECH}\par}%
|
||||
\vspace{0.08em}%
|
||||
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
|
||||
\end{minipage}%
|
||||
}%
|
||||
\end{minipage}%
|
||||
]{}[-3.1em]
|
||||
\normalmarginpar
|
||||
|
||||
\marginnote{%
|
||||
\begin{minipage}{\marginparwidth}%
|
||||
\raggedright
|
||||
{\fontsize{3.55}{3.95}\selectfont\ttfamily
|
||||
\hspace*{0.06cm}%
|
||||
\begin{minipage}[t]{\dimexpr\marginparwidth-0.06cm\relax}%
|
||||
\raggedright
|
||||
{\bfseries\textcolor{black!65}{OG}\par}%
|
||||
\vspace{0.08em}%
|
||||
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
|
||||
\end{minipage}%
|
||||
}%
|
||||
\end{minipage}%
|
||||
}[-3.1em]
|
||||
|
||||
|
||||
\begingroup
|
||||
\scriptsize\ttfamily\color{black!60}\sloppy
|
||||
\noindent drzewka: \pdftooltip[width=\textwidth]{D1}{K11.WE01.OG.LOCAL.OOP.RAII.04 | WE 01: Mutex i LockGuard. Bezpieczny scoped mutex z\textCR obserwowalnym priority inheritance. | EN LOCAL OOP.RAII.04: Analizuje ownership, scoped\textCR release i invalid recursive use. | KW LOCAL OOP.RAII.04: Dowodzi jednego give na każdej\textCR ścieżce i właściwych granic API.}\par
|
||||
\vspace{0.10em}%
|
||||
\noindent K1: Udowodnij exactly one unlock na każdej ścieżce.\quad D1\par
|
||||
\ESCTinyStepSeparator
|
||||
\noindent K2: Odrzuć recursive take ordinary mutexa.\quad D1\par
|
||||
\par\vspace{0.18em}%
|
||||
\endgroup
|
||||
|
||||
Porównaj mutex z binary semaphore, sprawdź owner-only give, non-recursive take i trzy early returns guarda.
|
||||
\ESCSectionBlockEnd
|
||||
|
||||
\ESCSectionBlockStart
|
||||
\section{LOW, MEDIUM, HIGH}
|
||||
\reversemarginpar
|
||||
\marginnote[%
|
||||
\begin{minipage}{\marginparwidth}%
|
||||
\raggedright
|
||||
{\fontsize{3.55}{3.95}\selectfont\ttfamily
|
||||
\begin{minipage}[t]{\marginparwidth}%
|
||||
\raggedright
|
||||
{\bfseries\textcolor{black!65}{TECH}\par}%
|
||||
\vspace{0.08em}%
|
||||
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
|
||||
\end{minipage}%
|
||||
}%
|
||||
\end{minipage}%
|
||||
]{}[-3.1em]
|
||||
\normalmarginpar
|
||||
|
||||
\marginnote{%
|
||||
\begin{minipage}{\marginparwidth}%
|
||||
\raggedright
|
||||
{\fontsize{3.55}{3.95}\selectfont\ttfamily
|
||||
\hspace*{0.06cm}%
|
||||
\begin{minipage}[t]{\dimexpr\marginparwidth-0.06cm\relax}%
|
||||
\raggedright
|
||||
{\bfseries\textcolor{black!65}{OG}\par}%
|
||||
\vspace{0.08em}%
|
||||
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
|
||||
\end{minipage}%
|
||||
}%
|
||||
\end{minipage}%
|
||||
}[-3.1em]
|
||||
|
||||
|
||||
\begingroup
|
||||
\scriptsize\ttfamily\color{black!60}\sloppy
|
||||
\noindent drzewka: \pdftooltip[width=\textwidth]{D1}{K11.WE01.TECH.LOCAL.RTOS.MUTEX.01 | WE 01: Mutex i LockGuard. Bezpieczny scoped mutex z\textCR obserwowalnym priority inheritance. | EK LOCAL RTOS.MUTEX.01: Mierzy priority inheritance,\textCR owner i harmonogram trzech tasków. | KW LOCAL RTOS.MUTEX.01: Pokazuje HIGH Blocked, LOW\textCR 1-3-1, MEDIUM after release i counter 11.}\par
|
||||
\vspace{0.10em}%
|
||||
\noindent K1: Zapisz HIGH=Blocked i holder=LOW.\quad D1\par
|
||||
\ESCTinyStepSeparator
|
||||
\noindent K2: Pokaż LOW current=3 przed MEDIUM.\quad D1\par
|
||||
\par\vspace{0.18em}%
|
||||
\endgroup
|
||||
|
||||
LOW bierze mutex, HIGH blokuje się, MEDIUM jest ready, a kernel podnosi LOW z 1 do 3.
|
||||
\ESCSectionBlockEnd
|
||||
|
||||
\ESCSectionBlockStart
|
||||
\section{Handoff i restore}
|
||||
\reversemarginpar
|
||||
\marginnote[%
|
||||
\begin{minipage}{\marginparwidth}%
|
||||
\raggedright
|
||||
{\fontsize{3.55}{3.95}\selectfont\ttfamily
|
||||
\begin{minipage}[t]{\marginparwidth}%
|
||||
\raggedright
|
||||
{\bfseries\textcolor{black!65}{TECH}\par}%
|
||||
\vspace{0.08em}%
|
||||
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
|
||||
\end{minipage}%
|
||||
}%
|
||||
\end{minipage}%
|
||||
]{}[-3.1em]
|
||||
\normalmarginpar
|
||||
|
||||
\marginnote{%
|
||||
\begin{minipage}{\marginparwidth}%
|
||||
\raggedright
|
||||
{\fontsize{3.55}{3.95}\selectfont\ttfamily
|
||||
\hspace*{0.06cm}%
|
||||
\begin{minipage}[t]{\dimexpr\marginparwidth-0.06cm\relax}%
|
||||
\raggedright
|
||||
{\bfseries\textcolor{black!65}{OG}\par}%
|
||||
\vspace{0.08em}%
|
||||
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
|
||||
\end{minipage}%
|
||||
}%
|
||||
\end{minipage}%
|
||||
}[-3.1em]
|
||||
|
||||
|
||||
\begingroup
|
||||
\scriptsize\ttfamily\color{black!60}\sloppy
|
||||
\noindent drzewka: \pdftooltip[width=\textwidth]{D1}{K11.WE01.TECH.LOCAL.RTOS.MUTEX.01 | WE 01: Mutex i LockGuard. Bezpieczny scoped mutex z\textCR obserwowalnym priority inheritance. | EK LOCAL RTOS.MUTEX.01: Mierzy priority inheritance,\textCR owner i harmonogram trzech tasków. | KW LOCAL RTOS.MUTEX.01: Pokazuje HIGH Blocked, LOW\textCR 1-3-1, MEDIUM after release i counter 11.}\par
|
||||
\vspace{0.10em}%
|
||||
\noindent K1: Potwierdź event order i holder=HIGH.\quad D1\par
|
||||
\ESCTinyStepSeparator
|
||||
\noindent K2: Potwierdź LOW=1 oraz protected counter=11.\quad D1\par
|
||||
\par\vspace{0.18em}%
|
||||
\endgroup
|
||||
|
||||
Guard LOW zwalnia, HIGH staje się ownerem, potem MEDIUM biegnie, a LOW wraca do priority 1.
|
||||
\ESCSectionBlockEnd
|
||||
|
||||
\end{document}
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
\documentclass[10pt]{article}
|
||||
\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}\usepackage[polish]{babel}
|
||||
\usepackage[a4paper,margin=1.55cm]{geometry}
|
||||
\usepackage{array,tabularx,booktabs,amsmath,amssymb,xcolor,listings,hyperref,fancyhdr,lastpage,enumitem}
|
||||
\definecolor{accent}{HTML}{16324A}\definecolor{accentlight}{HTML}{EEF3F7}\definecolor{rulegray}{HTML}{D7DEE5}
|
||||
\hypersetup{colorlinks=true,linkcolor=accent,urlcolor=blue}
|
||||
\IfFileExists{build-meta.tex}{\input{build-meta.tex}}{\newcommand{\BuildCommit}{local}}
|
||||
\newcommand{\PublisherDomain}{mpabi}
|
||||
\newcommand{\CardArea}{inf}
|
||||
\newcommand{\CardSeries}{freertos-cpp}
|
||||
\newcommand{\CardNumber}{11}
|
||||
\newcommand{\CardCount}{16}
|
||||
\newcommand{\CardSlug}{mutex}
|
||||
\newcommand{\CardVersion}{v00.01}
|
||||
\newcommand{\DocumentUUID}{34d7ad61-6b03-4922-8e58-b8b98316e5f7}
|
||||
\newcommand{\blank}[1]{\rule{#1}{.2pt}}
|
||||
\lstset{language=C++,basicstyle=\ttfamily\scriptsize,columns=fullflexible,keepspaces=true,frame=single,breaklines=true,showstringspaces=false,numbers=none,backgroundcolor=\color{accentlight},rulecolor=\color{rulegray}}
|
||||
\pagestyle{fancy}\fancyhf{}
|
||||
\lhead{\textbf{K11 · FreeRTOS C++ · mutex}}\rhead{\small L10 · owner + inheritance}
|
||||
\lfoot{\scriptsize commit \BuildCommit}\cfoot{\scriptsize \thepage/\pageref{LastPage}}\rfoot{\scriptsize V11.3.0 / \CardVersion}
|
||||
\setlength{\headheight}{14pt}\setlength{\footskip}{19pt}
|
||||
\setlist[itemize]{nosep,leftmargin=1.45em}\setlist[enumerate]{nosep,leftmargin=1.65em}
|
||||
\begin{document}\sloppy
|
||||
\begin{center}
|
||||
{\LARGE\bfseries \texttt{Mutex}, \texttt{LockGuard} i inheritance}\par
|
||||
\vspace{.25em}{\large owner, trzy early returns i zmiana LOW 1--3--1}\par
|
||||
\end{center}
|
||||
\noindent\begin{tabularx}{\textwidth}{@{}p{1.65cm}Xp{1.75cm}X@{}}
|
||||
\toprule
|
||||
Karta & K11 / \CardCount & Czas & 30 minut \\
|
||||
Platforma & Hazard3 / RV32I & Taski & LOW/MEDIUM/HIGH \\
|
||||
Priorytety & 1 / 2 / 3 & Storage & static, heap delta 0 \\
|
||||
Wersja & \CardVersion & UUID karty & \texttt{34d7ad61-...} \\
|
||||
\bottomrule
|
||||
\end{tabularx}
|
||||
|
||||
\section*{Dlaczego mutex nie jest binary semaphore?}
|
||||
\noindent\begin{tabularx}{\textwidth}{@{}p{4.3cm}p{4cm}X@{}}
|
||||
\toprule
|
||||
Właściwość & Mutex & Binary semaphore \\
|
||||
\midrule
|
||||
owner & tak & nie \\
|
||||
give & tylko owner & sygnał od producenta \\
|
||||
priority inheritance & tak & nie \\
|
||||
ISR give & nie & wariant FromISR istnieje \\
|
||||
\bottomrule
|
||||
\end{tabularx}
|
||||
|
||||
\noindent\fcolorbox{accent}{accentlight}{\begin{minipage}{.94\textwidth}
|
||||
\textbf{Kontrakt K11.} HIGH blokuje się na mutexie LOW. Kernel tymczasowo podnosi
|
||||
LOW do priorytetu HIGH, aby MEDIUM nie przedłużał inwersji. Destruktor guarda
|
||||
zwalnia dokładnie raz; ordinary mutex nie jest rekurencyjny ani ISR-safe.
|
||||
\end{minipage}}
|
||||
|
||||
\section*{Plan 30 minut}
|
||||
\noindent\begin{tabularx}{\textwidth}{@{}p{1.35cm}p{3.1cm}X@{}}
|
||||
\toprule Czas & Tryb & Dowód \\
|
||||
\midrule
|
||||
0--5 & semantics & owner, give i różnica od semaphore \\
|
||||
5--10 & guard & trzy return, jeden unlock na ścieżkę \\
|
||||
10--15 & setup & LOW bierze; HIGH próbuje; MEDIUM ready \\
|
||||
15--20 & inherit & HIGH blocked; LOW 1--3 \\
|
||||
20--25 & handoff & LOW przed MEDIUM; potem HIGH owner \\
|
||||
25--30 & restore & LOW wraca do 1; counter=11 \\
|
||||
\bottomrule
|
||||
\end{tabularx}
|
||||
|
||||
\section*{Predykcja}
|
||||
Kto wykona się po zablokowaniu HIGH: LOW czy MEDIUM? \blank{3cm}. Jaki będzie
|
||||
bieżący priorytet LOW? \blank{2cm}.
|
||||
|
||||
\newpage
|
||||
\section{LockGuard i granice ownership}
|
||||
\begin{lstlisting}
|
||||
{
|
||||
freertos::LockGuard<freertos::Mutex> guard{mutex, timeout};
|
||||
if (!guard.owns_lock()) return failed;
|
||||
// protected work; every return crosses guard destructor
|
||||
}
|
||||
\end{lstlisting}
|
||||
|
||||
\noindent\begin{tabularx}{\textwidth}{@{}p{1.5cm}p{3cm}p{3cm}X@{}}
|
||||
\toprule Path & Take & Give po return & Wynik \\
|
||||
\midrule
|
||||
0 & success & \blank{2cm} & \texttt{10} \\
|
||||
1 & success & \blank{2cm} & \texttt{20} \\
|
||||
2 & success & \blank{2cm} & \texttt{30} \\
|
||||
\bottomrule
|
||||
\end{tabularx}
|
||||
|
||||
\section*{Ordinary oznacza non-recursive}
|
||||
Ten sam task próbuje wziąć już posiadany mutex z timeout 0. Wynik:
|
||||
\blank{3cm}. Czy nieudany \texttt{LockGuard} może wywołać give w destruktorze?
|
||||
\blank{2cm}.
|
||||
|
||||
\section{Kontrolowany scenariusz inwersji}
|
||||
\begin{center}
|
||||
\texttt{LOW(1) take -- HIGH(3) attempt/block -- LOW inherits 3}\\[.25em]
|
||||
\texttt{LOW release -- HIGH take/give -- MEDIUM(2) run -- LOW back at 1}
|
||||
\end{center}
|
||||
|
||||
\noindent\begin{tabularx}{\textwidth}{@{}p{1.25cm}p{3.2cm}p{3.7cm}X@{}}
|
||||
\toprule Nr & Aktor & Zdarzenie & Odczyt \\
|
||||
\midrule
|
||||
1 & LOW & take, owner=LOW & \blank{2.4cm} \\
|
||||
2 & HIGH & attempt, state=Blocked & \blank{2.4cm} \\
|
||||
3 & LOW & priority inherited, release & \blank{2.4cm} \\
|
||||
4 & HIGH & take, owner=HIGH & \blank{2.4cm} \\
|
||||
5 & MEDIUM & pierwszy run & \blank{2.4cm} \\
|
||||
6 & LOW & priority restored & \blank{2.4cm} \\
|
||||
\bottomrule
|
||||
\end{tabularx}
|
||||
|
||||
Dlaczego MEDIUM nie może znaleźć się między krokiem 2 i release LOW?\\[.5em]
|
||||
\blank{16cm}
|
||||
|
||||
\newpage
|
||||
\section{Dowód priority inheritance}
|
||||
|
||||
\noindent\begin{tabularx}{\textwidth}{@{}p{5.4cm}p{3.2cm}X@{}}
|
||||
\toprule Pomiar & Predykcja & Odczyt \\
|
||||
\midrule
|
||||
LOW base priority & 1 & \blank{2.5cm} \\
|
||||
HIGH priority & 3 & \blank{2.5cm} \\
|
||||
HIGH state podczas wait & Blocked & \blank{2.5cm} \\
|
||||
LOW current podczas wait & 3 & \blank{2.5cm} \\
|
||||
MEDIUM ran before release & 0 & \blank{2.5cm} \\
|
||||
LOW po release & 1 & \blank{2.5cm} \\
|
||||
\bottomrule
|
||||
\end{tabularx}
|
||||
|
||||
\section{Owner i chroniony stan}
|
||||
\noindent\begin{tabularx}{\textwidth}{@{}p{5cm}p{3.7cm}X@{}}
|
||||
\toprule Relacja & Predykcja & Odczyt \\
|
||||
\midrule
|
||||
holder po LOW take & LOW handle & \blank{2.5cm} \\
|
||||
holder po handoff & HIGH handle & \blank{2.5cm} \\
|
||||
counter po LOW & 1 & \blank{2.5cm} \\
|
||||
counter po HIGH & 11 & \blank{2.5cm} \\
|
||||
mutex handle & caller control & \blank{2.5cm} \\
|
||||
heap delta create/destroy & 0 / 0 & \blank{2.5cm} \\
|
||||
\bottomrule
|
||||
\end{tabularx}
|
||||
|
||||
\section*{Co inheritance rozwiązuje, a czego nie?}
|
||||
Rozwiązuje ograniczoną inwersję powodowaną przez ownera mutexa. Nie skraca
|
||||
długiej sekcji, nie naprawia deadlocku, nie nadaje porządku wielu mutexom i nie
|
||||
pozwala zwolnić mutexa z innego taska.
|
||||
|
||||
Zaproponuj stały porządek przejmowania dwóch mutexów A/B:\\[.5em]
|
||||
\blank{16cm}\\[1em]
|
||||
Co stanie się z inheritance, gdy LOW trzyma kilka mutexów?\\[.5em]
|
||||
\blank{16cm}
|
||||
|
||||
\section*{Kontrakt czasu}
|
||||
Timeout w konstruktorze guarda jest jawny. \texttt{portMAX\_DELAY} w tym
|
||||
eksperymencie jest świadomym oczekiwaniem HIGH, nie ukrytym defaultem API.
|
||||
|
||||
\newpage
|
||||
\section{Hazard3/GDB i zaliczenie}
|
||||
\begin{lstlisting}[language=bash]
|
||||
make check
|
||||
riscv64-unknown-elf-gdb build/task01_mutex/prog.elf
|
||||
b mutex_debug_checkpoint
|
||||
\end{lstlisting}
|
||||
\begin{lstlisting}
|
||||
p g_low_base_priority
|
||||
p g_low_inherited_priority
|
||||
p g_low_priority_after_release
|
||||
p g_high_state_seen_by_low
|
||||
p g_medium_ran_before_release
|
||||
p/x g_owner_low
|
||||
p/x g_owner_high
|
||||
p g_sequence_low_take
|
||||
p g_sequence_high_attempt
|
||||
p g_sequence_low_release
|
||||
p g_sequence_high_take
|
||||
p g_sequence_medium_run
|
||||
p g_shared_counter
|
||||
p g_mutex_pass
|
||||
\end{lstlisting}
|
||||
|
||||
\section*{Zaliczenie}
|
||||
\begin{itemize}
|
||||
\item $\square$ odróżniam mutex owner/inheritance od binary semaphore;
|
||||
\item $\square$ pokazuję give guarda na trzech early returns;
|
||||
\item $\square$ dowodzę HIGH=Blocked i LOW 1--3--1;
|
||||
\item $\square$ MEDIUM nie wykonuje się przed release LOW;
|
||||
\item $\square$ owner równa się właściwemu handle LOW/HIGH;
|
||||
\item $\square$ event order i chroniony counter=11 kończą się PASS.
|
||||
\end{itemize}
|
||||
|
||||
\section*{Wyjście}
|
||||
Dlaczego binary semaphore nie naprawi tej inwersji?\\[.5em]\blank{16cm}\\[1em]
|
||||
Dlaczego ordinary mutex nie wolno brać drugi raz?\\[.5em]\blank{16cm}
|
||||
|
||||
\vfill
|
||||
\noindent\textbf{Następna karta K12:} binary/counting semaphore oraz
|
||||
jednoodbiorcze task notifications z porównaniem storage i semantyki.
|
||||
\end{document}
|
||||
BIN
Binary file not shown.
Reference in New Issue
Block a user