Skip to content

An upgraded 'Shared' macro allows a definition of the internal queue size on a per-object-basis. #70

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
Jun 23, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions docs/02-data-exchange.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ A `Shared` variable is a global variable accessible to all threads. It can be de
```C++
/* SharedVariables.h */
SHARED(counter, int); /* A globally available, threadsafe, shared variable of type 'int'. */
/* ... or ... */
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`, ...
Expand Down
3 changes: 3 additions & 0 deletions src/Arduino_Threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public: \
#define SHARED(name, type) \
Shared<type> name;

#define SHARED(name, type, size) \
Shared<type, size> name;

#define ARDUINO_THREADS_CONCAT_(x,y) x##y
#define ARDUINO_THREADS_CONCAT(x,y) ARDUINO_THREADS_CONCAT_(x,y)

Expand Down