Skip to content

Change description to use push/pop function #75

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 2 commits into from
Jul 13, 2022
Merged
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions docs/02-data-exchange.md
Original file line number Diff line number Diff line change
@@ -16,15 +16,15 @@ SHARED(counter, int); /* A globally available, threadsafe, shared variable of ty
SHARED(counter, int, 8); /* Same as before, but now the internal queue size is defined as 8. */
```
Writing to and reading from the shared variable may not always happen concurrently. I.e. a thread reading sensor data may update the shared variable faster than a slower reader thread would extract those values. Therefore the shared variable is modeled as a queue which can store (buffer) a certain number of entries. That way the slower reader thread can access all the values in the same order as they have been written.
New values can be inserted naturally by using the assignment operator `=` as if it was just any ordinary variable type, i.e. `int`, `char`, ...
New values can be inserted by using the `push` function that you may know from other data structures.
```C++
/* Thread_1.inot */
counter.push(10); /* Store a value into the shared variable in a threadsafe manner. */
```
If the internal queue is full the oldest element is discarded and the latest element is inserted into the queue.

Retrieving stored data works also very naturally like it would for any POD data type:
Stored data can be retrieved by using the `pop` function:
```C++
/* Thread_2.inot */
Serial.println(counter.pop()); /* Retrieves a value from the shared variable in a threadsafe manner. */