Skip to Content
Embedded Programming with Modern C++ Cookbook
book

Embedded Programming with Modern C++ Cookbook

by Igor Viarheichyk
April 2020
Intermediate to advanced
412 pages
9h 58m
English
Packt Publishing
Content preview from Embedded Programming with Modern C++ Cookbook

How it works...

In our application, we created two functions, sleep_for and sleep_until. They are almost identical, except sleep_for uses std::this_thread::sleep_for to add a delay, while sleep_until uses std::this_thread::sleep_until.

Let's take a closer look at the sleep_for function. It takes two parameters—count and delay. The first parameter defines a number of iterations in its loop, and the second parameter specifies a delay. We use auto as a data type of the delay parameter, letting C++ infer the actual data type for us.

The function body consists of a single loop:

  for (int i = 0; i < count; i++) {

On each iteration, we run the delay and measure its actual duration by taking timestamps before and after the delay. The std::this_thread::sleep_for ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C++ System Programming Cookbook

C++ System Programming Cookbook

Onorato Vaticone
C++ Cookbook

C++ Cookbook

D. Ryan Stephens, Christopher Diggins, Jonathan Turkanis, Jeff Cogswell

Publisher Resources

ISBN: 9781838821043Supplemental Content