C++ Multithreading with Thread and Async
Channel:
Subscribers:
2,650
Published on ● Video Link: https://www.youtube.com/watch?v=FxfHC7_s3NI
It's not too bad to get code to run on other CPUs in modern C++. You just do something like this:
thread t(foo); //Runs the function foo() on another CPU
Then:
t.join(); //Waits for foo() to finish
Or:
t.detach(); //Don't wait for foo() to finish, it can do its own thing
What CPU does it run on? It's up to the thread scheduler, it might be a different CPU, it might even be your own.
Multithreading is nice and easy when working with pure functions (functions with no side effect), but if you are going to be accessing shared resources, use a mutex / lock_guard to protect the shared_resource so only one thread can touch it at a time
Other Videos By Bill Kerney
2023-08-16 | C++ Conditionals (If Statements / Branches) |
2023-08-16 | C++ Shortcuts |
2023-08-16 | UNIX Shortcuts |
2023-08-11 | Lab Time #1 - Elementary |
2023-08-10 | UE5: Intro to Materials |
2023-08-10 | Intro to Rasterization and Shaders |
2023-08-09 | C++ Basics: Printing to the Screen, Creating Variables, Doing Algebra, and Input |
2023-08-08 | Getting Started with Unreal Engine 5 |
2023-08-01 | How to Log On to the Class UNIX Server and Use It For the First Time |
2023-05-17 | CMake Tutorial (ACM Workshop by Aaron Herr) |
2023-05-15 | C++ Multithreading with Thread and Async |
2023-05-13 | CSCI 41: End of the Semester |
2023-05-13 | Introduction to Graph Theory |
2023-05-12 | C++ Networking as easy as it can be |
2023-05-10 | Final Review |
2023-05-08 | Exceptions and TDD |
2023-05-08 | Symbols, Semantics, Definitions and Meaning. |
2023-05-05 | The Final Project Volleyshipardy |
2023-05-05 | The Software Development Lifecycle |
2023-05-05 | Setting up Github for Two Person Projects |
2023-05-03 | Bitfields Part III |