C++ Threads in 11 minutes
It's actually more like 5 minutes, but I did go over a few optional items as well.
Basically to make a thread in C++, you include thread, and then make a thread object like this:
thread obj_name(func_name);
Obj_name is the name of the variable (I used USA, but you can call it anything), and func_name is the name of the function to run. It will go off and run in its own thread at the same time as your current code is running. Neat stuff.
Sharp Edge 1: You have to either .detach() the thread to let it run and do its own thing forever, or you have to .join() it when you want to wait for it to end. If you don't do either, it will cause problems. So pick one. For this one, I just detached it since it can figure out when to end on its own.
Sharp Edge 2: To compile the code, compile with -pthread or it won't work.
Other Videos By Bill Kerney
2022-05-11 | Introduction to Graph Theory |
2022-05-11 | Python in 45 minutes |
2022-05-09 | Sample Project - Grocery Store |
2022-05-09 | Evaluating Media Sources |
2022-05-06 | Threads and Sockets Programming in Java |
2022-05-06 | Java for the C++ Programmer in 1 Hour |
2022-05-06 | Automation and the Chip Shortage |
2022-05-04 | C++ Trivia Quiz |
2022-05-04 | Threads II: Atomics, Mutexes, Thread-Specific Variables |
2022-05-04 | Binary Representations + Digital Ownership |
2022-05-02 | C++ Threads in 11 minutes |
2022-05-02 | Consciousness |
2022-04-29 | Tries Part II, Huffman Coding |
2022-04-29 | Python in 50 minutes |
2022-04-27 | Tries |
2022-04-27 | Set Theory: Different Sized Infinities; Brief intro to Python |
2022-04-26 | Quadtrees (Pt II), K-D Trees, BSP Trees, AABBs vs OBBs |
2022-04-25 | Composite Data Structures |
2022-04-25 | Symbolism and Semantics |
2022-04-23 | Shapes (Linear Algebra review), Bitwise Operations Part II, Vim Macros |
2022-04-22 | Sea Shanty Workshop |