From the course: Modern C++: Advanced Techniques and Features
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Multithreading - C++ Tutorial
From the course: Modern C++: Advanced Techniques and Features
Multithreading
- In this section, we're going to start to look at how to do multithreading in C++. There was a time in early C++ where threading wasn't actually defined in the standard library. You'd have to use an operating system, API, you'd have to use the Linux API or the Windows API, which is obviously not portable across different operating systems. But nowadays, there is a standard thread in API and C++. We're going to start to see how to use it in this section. So first of all, include the thread header, And in the thread header, it defines std thread. So you create a thread object and you give it a callable object. So for example, the name of a function. myfunc1 is a function. When you create a thread object, the thread object creates a system thread underneath the surface and executes your function on that thread. So this function would be doing some kind of background work probably, at the same time as the main thread continues to execute. So if your main thread is going to potentially…