Skip to content

Commit 33fb1ce

Browse files
authored
Cleaning up/adding missing comments within examples. (#58)
This is done in order to put clearer into context what actually is happening.
1 parent 7d503b2 commit 33fb1ce

File tree

19 files changed

+89
-18
lines changed

19 files changed

+89
-18
lines changed

examples/Breaks_6/Breaks_6.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/* This example is in fact expected to break, since we try
2+
* to access a thread-private variable.
3+
*/
4+
15
#include <Arduino_Threads.h>
26

37
void setup()

examples/Threading_Basics/Shared_Counter/Consumer.inot

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,11 @@ void setup()
66

77
void loop()
88
{
9+
/* If a value is available for reading within the internal
10+
* queue then the value is removed from the queue and made
11+
* available to the calling function. Should no data be
12+
* available, then this thread is suspended until new data
13+
* is available for reading.
14+
*/
915
Serial.println(counter);
1016
}

examples/Threading_Basics/Shared_Counter/Producer.inot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ void setup()
66
void loop()
77
{
88
static int i = 0;
9+
/* Every 100 ms a new value is inserted into the shared variable
10+
* 'counter'. Internally this is stored within a queue in a FIFO
11+
* (First-In/First-Out) manner.
12+
*/
913
counter = i;
1014
i++;
1115
delay(100);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
/* Define a shared variable named 'counter' of type 'int'. */
12
SHARED(counter, int);

examples/Threading_Basics/Shared_Counter/Shared_Counter.ino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/* This example demonstrates data exchange between
2+
* threads using a shared counter variable defined
3+
* within 'SharedVariables.h'.
4+
*/
5+
16
void setup()
27
{
38
Producer.start();

examples/Threading_Basics/Source_Sink_Counter/Consumer.inot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* Define a data sink named 'counter' of type 'int' with a internal queue size of 10. */
12
SINK(counter, int, 10);
23

34
void setup()

examples/Threading_Basics/Source_Sink_Counter/Producer.inot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* Define a data source named 'counter' of type 'int'. */
12
SOURCE(counter, int);
23

34
void setup()

examples/Threading_Basics/Source_Sink_Counter/Source_Sink_Counter.ino

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
/*
2-
* This examples demonstrates the SOURCE/SINK abstraction.
3-
* Each thread may have any number of SOURCES and SINKS that can be connected
4-
* together using the "connectTo" method.
1+
/* This examples demonstrates the SOURCE/SINK abstraction. Each thread
2+
* may have any number of SOURCES and SINKS that can be connected
3+
* together using the 'connectTo' method.
54
*/
65

76
void setup()
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
2-
/*
3-
* An 'bool' SINK with a size of '0'. This kind of SINK has no buffer so the reading thread
4-
* will block until the writing thread has written something, or vice versa.
5-
*/
1+
/* Define a data sink named 'led' of type 'bool' with a internal queue size of 1. */
62
SINK(led, bool);
73

84
void setup()
@@ -12,9 +8,9 @@ void setup()
128

139
void loop()
1410
{
15-
/* Read a 'bool' from the SINK and discard it. Since there is basically no delay in the loop
16-
* this call will surely block until something comes from the connected SOURCE. In this case
17-
* the pace is dictated by the SOURCE that sends data every 100 ms.
11+
/* Read a 'bool' value from the SINK and discard it. Since there is no delay in the loop
12+
* this call will block until new data is inserted from the connected SOURCE. This means
13+
* that the pace is dictated by the SOURCE that sends data every 100 ms.
1814
*/
1915
digitalWrite(LED_BUILTIN, led);
2016
}

examples/Threading_Basics/Source_Sink_LED/Source_Sink_LED.ino

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
/*
2-
* This examples demonstrates the SOURCE/SINK abstraction.
3-
* Each thread may have any number of SOURCES and SINKS that can be connected
4-
* together using the "connectTo" method.
1+
/* This examples demonstrates the SOURCE/SINK abstraction. Each thread
2+
* may have any number of SOURCES and SINKS that can be connected
3+
* together using the 'connectTo' method.
54
*/
65

76
void setup()

0 commit comments

Comments
 (0)