Skip to content

Commit 1be8f61

Browse files
authored
Bugfix: Yield after every execution of 'loop' if a loop delay of 0 is specified. (#38)
Otherwise we experience ressource starvation with the first started thread hogging the CPU all the time and the other threads will be never served.
1 parent fe08f19 commit 1be8f61

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Diff for: src/Arduino_Threads.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,17 @@ void Arduino_Threads::threadFunc()
118118
}
119119
}
120120

121-
/* Sleep for the time we've been asked to insert between loops.
122-
*/
123-
rtos::ThisThread::sleep_for(rtos::Kernel::Clock::duration_u32(_loop_delay_ms));
121+
if (_loop_delay_ms) {
122+
/* Sleep for the time we've been asked to insert between loops.
123+
*/
124+
rtos::ThisThread::sleep_for(rtos::Kernel::Clock::duration_u32(_loop_delay_ms));
125+
}
126+
else
127+
{
128+
/* In any case yield here so that other threads can also be
129+
* executed following the round-robin scheduling paradigm.
130+
*/
131+
rtos::ThisThread::yield();
132+
}
124133
}
125134
}

0 commit comments

Comments
 (0)