@@ -79,7 +79,8 @@ if(myThread.shouldRun()){
7979
8080Now 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?!?
8181
82- * The answer is: NO. Create a ` ThreadController ` , and put all your boring-complex Threads inside it!
82+ * The answer is: NO. Create a ` ThreadController ` or ` StaticThreadController ` ,
83+ and put all your boring-complex Threads inside it!
8384
8485``` c++
8586// Instantiate a new ThreadController
@@ -90,11 +91,18 @@ controller.add(&hisThread);
9091controller.add(&sensorReadings);
9192...
9293```
94+ or
95+ ``` c++
96+ // Instantiate a new StaticThreadController
97+ StaticThreadController<2 > controller (Thread(my_callback, my_interval), Thread(his_callback, his_interval));
98+ // You don't need to do anything else, the treads will be created and kept inside controller
99+ ...
100+ ```
93101
94102* You have created, configured, grouped it. What is missing? Yes, whe should RUN it!
95103
96104```c++
97- // call run on a Thread or a ThreadController to run it
105+ // call run on a Thread, a ThreadController or a StaticThreadController to run it
98106controller.run();
99107```
100108
@@ -126,6 +134,11 @@ or disable a GROUP of Threads, think about putting all of them inside a ThreadCo
126134and adding this ThreadController to another ThreadController (YES! One ThreadController
127135inside another). Check ` ControllerInController ` example.
128136
137+ * There is a ` StaticThreadController ` which is better to use when you know exact number of
138+ threads to run. You cannot add or remove threads in runtime, but ` StaticThreadController `
139+ doesn't have any memory overhead to keep all the treads together, also the code may be slighly
140+ more optimized because all the threads always exist and no need to do any runtime checks.
141+
129142* Check the full example ` CustomTimedThread ` for a cool application of Threads that runs
130143for a period, after a button is pressed.
131144
@@ -177,5 +190,12 @@ interrupts(); // This will enable the interrupts egain. DO NOT FORGET!
177190 inside the ThreadController. If cached is ` false ` , will force the calculation of threads.
178191- ` Thread* ThreadController::get(int index) ` - Returns the Thread on the position ` index ` .
179192
193+
194+ - ` void StaticThreadController::run() ` - This will run the all ` Threads ` within the ` StaicThreadController ` ,
195+ only if needed (if shouldRun returns true);
196+ - ` int StaticThreadController::size() ` - Returns how many Threads are allocated inside the StaticThreadController.
197+ - ` Thread* ThreadController::get(int index) ` - Returns the Thread on the position ` index ` and ` nullptr ` if ` index `
198+ is out of bounds.
199+
180200### You don't need to know:
181201- Nothing, yet ;)
0 commit comments