feur
This commit is contained in:
parent
a4331aaad2
commit
bf19b0b29a
4 changed files with 105 additions and 0 deletions
8
os/tp2/doc/application.plantuml
Normal file
8
os/tp2/doc/application.plantuml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
@startuml application
|
||||||
|
title Application
|
||||||
|
|
||||||
|
object task1 {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@enduml
|
97
os/tp2/doc/rapport.md
Normal file
97
os/tp2/doc/rapport.md
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
# Rapport de TP2 de SEPT
|
||||||
|
|
||||||
|
> Matthieu Jolimaitre & Quentin Harro
|
||||||
|
|
||||||
|
## Sémaphore
|
||||||
|
|
||||||
|
Une sémaphore est un objet partagé entre les fonctions de plusieurs fils
|
||||||
|
d'exécutions :
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
static SemaphoreHandle_t semaphore;
|
||||||
|
```
|
||||||
|
|
||||||
|
Une tâche peut libérer le sémaphore de cette manière :
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
void task_1(void* params) {
|
||||||
|
printf("[Task 1] start\n");
|
||||||
|
while (1) {
|
||||||
|
xSemaphoreGive(semaphore);
|
||||||
|
printf("[Task 1] gave semaphore\n");
|
||||||
|
vTaskDelay(_3_SECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> _note_ : Ici, la sémaphore est libérée périodiquement toute les 4 secondes.
|
||||||
|
|
||||||
|
Une autre tâche peut attendre la libération de cette sémaphore de cette manière
|
||||||
|
:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
void task_2(void* params) {
|
||||||
|
printf("[Task 2] start\n");
|
||||||
|
while (1) {
|
||||||
|
printf("[Task 2] waiting semaphore\n");
|
||||||
|
xSemaphoreTake(semaphore, portMAX_DELAY);
|
||||||
|
printf("[Task 2] took semaphore\n");
|
||||||
|
printf("[Task 2] Message from task 2\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Nous sommes donc assurés que la tâche 2 exécutera systématiquement sa section
|
||||||
|
critique après celle de la tâche 1.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
> _note_ : Ici, la tâche attend périodiquement la libération de la sémaphore.
|
||||||
|
|
||||||
|
## Queue
|
||||||
|
|
||||||
|
Une queue est un objet partagé entre les fonctions de plusieurs fils
|
||||||
|
d'exécutions :
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
static QueueHandle_t queue;
|
||||||
|
```
|
||||||
|
|
||||||
|
Une tâche peut enfiler une valeur dans la queue de cette manière :
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
void task_1(void* params) {
|
||||||
|
printf("[Task 1] start\n");
|
||||||
|
while (1) {
|
||||||
|
auto ticks = xTaskGetTickCount();
|
||||||
|
printf("[Task 1] sending %lu to queue\n", ticks);
|
||||||
|
xQueueSend(queue, &ticks, portMAX_DELAY);
|
||||||
|
vTaskDelay(_1_SECOND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> _note_ : Ici, la tâche enfile périodiquement une empreinte temporelle dans la
|
||||||
|
> queue.
|
||||||
|
|
||||||
|
Une tâche peut ensuite itérer de manière bloquante sur les valeurs enfilés dans
|
||||||
|
la queue :
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
void task_2(void* params) {
|
||||||
|
printf("[Task 2] start\n");
|
||||||
|
while (1) {
|
||||||
|
TickType_t result;
|
||||||
|
xQueueReceive(queue, &result, portMAX_DELAY);
|
||||||
|
printf("[Task 2] Received %lu from queue\n", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> _note_ : Ici, la tâche itère sur les empreintes temporelles que la tâche
|
||||||
|
> précédente enfile.
|
||||||
|
|
||||||
|
Nous pouvons donc transférer un contexte d'un fil d'exécution à un autre sans
|
||||||
|
risque de corruption.
|
||||||
|
|
||||||
|

|
BIN
os/tp2/doc/rapport.odt
Normal file
BIN
os/tp2/doc/rapport.odt
Normal file
Binary file not shown.
BIN
os/tp2/doc/rapport.pdf
Normal file
BIN
os/tp2/doc/rapport.pdf
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue