Skip to content

Multi threading examples (tasks, queues, semaphores, mutexes) #7660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Feb 8, 2023
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Increased stack size for Sempahore example
  • Loading branch information
PilnyTomas committed Jan 23, 2023
commit a1dcca8485dd5b480c0b1ce83beab6c221e6a2b8
10 changes: 4 additions & 6 deletions libraries/MultiThreading/examples/Semaphore/Semaphore.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ void delivery_truck_task(void *pvParameters) {
// ...
// Notify the warehouse that a package has been delivered
xSemaphoreGive(package_delivered_semaphore);
Serial.print("Package delivered by truck: ");
Serial.println(truck_number);
Serial.printf("Package delivered by truck: %d\n", truck_number);
//wait for some time
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
Expand All @@ -23,8 +22,7 @@ void warehouse_worker_task(void *pvParameters) {
while(1) {
// Wait for a package to be delivered
xSemaphoreTake(package_delivered_semaphore, portMAX_DELAY);
Serial.print("Package received by worker: ");
Serial.println(worker_number);
Serial.printf("Package received by worker: %d\n", worker_number);
// Receive the package
// ...
}
Expand All @@ -38,12 +36,12 @@ void setup() {

// Create multiple delivery truck tasks
for (int i = 0; i < 5; i++) {
xTaskCreate(delivery_truck_task, "Delivery Truck", 512, (void *)i, tskIDLE_PRIORITY, NULL);
xTaskCreate(delivery_truck_task, "Delivery Truck", 2048, (void *)i, tskIDLE_PRIORITY, NULL);
}

// Create multiple warehouse worker tasks
for (int i = 0; i < 3; i++) {
xTaskCreate(warehouse_worker_task, "Warehouse Worker", 512, (void *)i, tskIDLE_PRIORITY, NULL);
xTaskCreate(warehouse_worker_task, "Warehouse Worker", 2048, (void *)i, tskIDLE_PRIORITY, NULL);
}
}

Expand Down