@@ -32,15 +32,18 @@ It should be noted that these are not “threads” in the real computer-science
3232There are many examples showing many ways to use it. Here, we will explain Class itself,
3333what it does and "how" it does.
3434
35- There are basicaly, two Classes included in this Library:
36- ` Thread ` and ` ThreadController ` (that inherits from Thread).
35+ There are basicaly, three Classes included in this Library:
36+ ` Thread ` , ` ThreadController ` and ` StaticThreadController ` (both controllers inherit from Thread).
3737
3838- ` Thread class ` : This is the basic class, witch contains methods to set and run callbacks,
3939 check if the Thread should be runned, and also creates a unique ThreadID on the instantiation.
4040
4141- ` ThreadController class ` : Responsable for "holding" multiple Threads. Can also be called
4242 as "a group of Threads", and is used to perform run in every Thread ONLY when needed.
4343
44+ - ` StaticThreadController class ` : Slighly faster and smaller version of ` ThreadController ` .
45+ It works similar to ` ThreadController ` , but once constructed it can't add or remove threads to run.
46+
4447* The instantiation of a Thread class is very simple:
4548
4649``` c++
@@ -79,7 +82,8 @@ if(myThread.shouldRun()){
7982
8083Now that you got the idea, let's think a little bit: What if i have 3, 5, 100 Threads. Do I need to check EACH one?!?
8184
82- * The answer is: NO. Create a ` ThreadController ` , and put all your boring-complex Threads inside it!
85+ * The answer is: NO. Create a ` ThreadController ` or ` StaticThreadController ` ,
86+ and put all your boring-complex Threads inside it!
8387
8488``` c++
8589// Instantiate a new ThreadController
@@ -90,11 +94,18 @@ controller.add(&hisThread);
9094controller.add(&sensorReadings);
9195...
9296```
97+ or
98+ ``` c++
99+ // Instantiate a new StaticThreadController with the number of threads to be supplied as template parameter
100+ StaticThreadController<3 > controller (&myThread, &hisThread, &sensorReadings);
101+ // You don't need to do anything else, controller now contains all the threads.
102+ ...
103+ ```
93104
94105* You have created, configured, grouped it. What is missing? Yes, whe should RUN it!
95106
96107```c++
97- // call run on a Thread or a ThreadController to run it
108+ // call run on a Thread, a ThreadController or a StaticThreadController to run it
98109controller.run();
99110```
100111
@@ -126,6 +137,12 @@ or disable a GROUP of Threads, think about putting all of them inside a ThreadCo
126137and adding this ThreadController to another ThreadController (YES! One ThreadController
127138inside another). Check ` ControllerInController ` example.
128139
140+ * There is a ` StaticThreadController ` which is better to use when you know exact number of
141+ threads to run. You cannot add or remove threads in runtime, but ` StaticThreadController `
142+ doesn't have additional memory overhead to keep all the treads together, doesn't have any
143+ limitations how many threads to store (except of available memory) and also the code may be slighly
144+ more optimized because all the threads always exist and no need to do any runtime checks.
145+
129146* Check the full example ` CustomTimedThread ` for a cool application of Threads that runs
130147for a period, after a button is pressed.
131148
@@ -177,5 +194,12 @@ interrupts(); // This will enable the interrupts egain. DO NOT FORGET!
177194 inside the ThreadController. If cached is ` false ` , will force the calculation of threads.
178195- ` Thread* ThreadController::get(int index) ` - Returns the Thread on the position ` index ` .
179196
197+
198+ - ` void StaticThreadController::run() ` - This will run the all ` Threads ` within the ` StaicThreadController ` ,
199+ only if needed (if shouldRun returns true);
200+ - ` int StaticThreadController::size() ` - Returns how many Threads are allocated inside the StaticThreadController.
201+ - ` Thread* ThreadController::get(int index) ` - Returns the Thread on the position ` index ` and ` nullptr ` if ` index `
202+ is out of bounds.
203+
180204### You don't need to know:
181205- Nothing, yet ;)
0 commit comments