-
Book Overview & Buying
-
Table Of Contents
C++ STL Cookbook - Second Edition
By :
A thread is a unit of concurrent execution. The main() function may be thought of as the main thread of execution. Within the context of the operating system, the main thread runs concurrently with other threads owned by other processes.
The std::thread class is the primary interface for creating threads in the C++ Standard Library. In this recipe we will examine the basics of std::thread, and how join() and detach() determine its execution context.
In this recipe we will create some threads using std::thread, and experiment with their execution options.
void sleepms(const unsigned ms) {
using std::chrono::milliseconds;
std::this_thread::sleep_for(milliseconds(ms));
}
The sleep_for() function takes a duration object and blocks execution of the current thread for the specified duration. This sleepms() function...