Multithreading in C++
What is multithreading?
There are a few definitions, depending on the point of view. From the CPU’s perspective, a multi-core processor that can execute multiple threads of instructions concurrently is real multithreading. From an application’s perspective, using multiple threads is multithreading. From a developer’s perspective, more focus might be on thread safety and various synchronization mechanisms, which are not multithreading itself, but its implications.
In this section, we will learn how to use Lua with C++’s native multithreading support. Each C++ thread will have its own Lua state. Because the Lua library does not keep any state and Lua states are not shared among different threads, this is thread-safe.
How does C++ support multithreading?
Since C++11, the standard library supports multithreading with std::thread
. Each std::thread
instance represents a thread of execution. The most important thing to provide...