1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-17 18:43:50 +01:00
AnnsAnn 55fa531e02 examples: restructure to use subfolders based on README structure
examples: Fix incorrect category heading

examples: shorten coap folder name

static-tests/examples: check subfolders for entries

ci/test_native: Adjust to new examples structure

examples: adjust makefiles to new structure

ci/tests: Fix symlinks to point towards proper examples
2025-02-13 11:54:09 +01:00

1.1 KiB

Rust: Asynchronous programming

This is an example of how asynchronous Rust applications can be written on RIOT OS.

The application starts an embassy based executor, and then spawn several tasks on the main thread. Unlike RIOT OS threads, these tasks can not preempt each other; they relinquish control of the main thread when performing an asynchronous operation that would block, and are paused by anything that preempts the main thread.

Behind the scenes, the Rust compiler turns the asynchronous methods into state machines, and the executor polls the state machines to make progress whenever an event wakes them up.

Upsides of this style of programming are that there is less need for synchronization (for individual tasks or their parts can rely on the work they do synchronously not to be executed concurrently with other tasks if so configured), and that they can share a single stack space. State that is persisted across await points is not stored on the stack, but in adequately sized static memory for each task that can run.