You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/02-data-exchange.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -18,14 +18,14 @@ New values can be inserted naturally by using the assignment operator `=` as if
18
18
19
19
```C++
20
20
/* Thread_1.inot */
21
-
counter = 10; /* Store a value into the shared variable in a threadsafe manner. */
21
+
counter.push(10); /* Store a value into the shared variable in a threadsafe manner. */
22
22
```
23
23
If the internal queue is full the oldest element is discarded and the latest element is inserted into the queue.
24
24
25
25
Retrieving stored data works also very naturally like it would for any POD data type:
26
26
```C++
27
27
/* Thread_2.inot */
28
-
Serial.println(counter); /* Retrieves a value from the shared variable in a threadsafe manner. */
28
+
Serial.println(counter.pop()); /* Retrieves a value from the shared variable in a threadsafe manner. */
29
29
```
30
30
31
31
Should the internal queue be empty when trying to read the latest available value then the thread reading the shared variable will be suspended and the next available thread will be scheduled. Once a new value is stored inside the shared variable the suspended thread resumes operation and consumes the value which has been stored in the internal queue.
Whenever a new value is assigned to a data source, i.e.
56
56
```C++
57
57
/* DataProducerThread.inot */
58
-
counter = 10;
58
+
counter.push(10);
59
59
```
60
60
data is automatically copied and stored within the internal queues of all connected data sinks, from where it can be retrieved, i.e.
61
61
```C++
62
62
/* DataConsumerThread_1.inot */
63
-
Serial.println(counter);
63
+
Serial.println(counter.pop());
64
64
```
65
65
```C++
66
66
/* DataConsumerThread_2.inot */
67
-
Serial.println(counter);
67
+
Serial.println(counter.pop());
68
68
```
69
69
If a thread tries to read from an empty `Sink` the thread is suspended and the next ready thread is scheduled. When a new value is written to a `Source` and consequently copied to a `Sink` the suspended thread is resumed and continuous execution (i.e. read the data and act upon it).
0 commit comments