11---
2- title : " Why ` std::this_thread::sleep_for()` is broken on ESP32"
2+ title : " Why std::this_thread::sleep_for() is broken on ESP32"
33description :
4- A deep dive into how ` std::this_thread::sleep_for()` is implemented on ESP32,
4+ A deep dive into how std::this_thread::sleep_for() is implemented on ESP32,
55 and why it is broken in IDF v5.
66author : stevenoonan
77tags : [esp32, freertos, c++, c, idf]
@@ -208,11 +208,11 @@ Let's look at the working side of things first. When calling
208208` std::this_thread::sleep_for(10ms) ` we first enter here:
209209
210210``` c++
211- // / sleep_for
212- template <typename _Rep, typename _Period>
213- inline void
214- sleep_for (const chrono::duration<_ Rep, _ Period>& __ rtime)
215- {
211+ // / sleep_for
212+ template <typename _Rep, typename _Period>
213+ inline void
214+ sleep_for (const chrono::duration<_ Rep, _ Period>& __ rtime)
215+ {
216216 if (__ rtime <= __ rtime.zero())
217217 return;
218218 auto __ s = chrono::duration_cast< chrono::seconds > (__ rtime);
@@ -228,7 +228,7 @@ Let's look at the working side of things first. When calling
228228#else
229229 __ sleep_for(__ s, __ ns);
230230#endif
231- }
231+ }
232232```
233233
234234If you are following along in your own IDF project, you can find the
@@ -299,7 +299,6 @@ Let's clean it up by taking out the parts not compiled for the ESP32:
299299 ::usleep(__ us);
300300 }
301301 }
302- }
303302```
304303
305304Pretty simple: get the number of seconds and call `sleep()`, then get the number
0 commit comments