Threads II: Atomics, Mutexes, Thread-Specific Variables
Today we talked about how to handle conflicts that can occur when multithreading when two threads access the same variable at the same time.
One way is to use atomic integers, which have the ability to be added to and subtracted from without violating the laws of time and space.
Mutual Exclusion - Mutexes are a more generally useful solution - basically you can start a block of code with a lock_guard attached to a mutex, and then only one thread can be in that block of code at a time. Nice!
Thread-specific variables means splitting up a variable into a bunch of variables, and then after all the threads finish, add them together or whatever. For example, if you want to find the maximum value in an array, you can have each thread report its value in its own global variable, and then main() can print to the screen the biggest one.
Other Videos By Bill Kerney
2022-05-13 | End of the Year |
2022-05-13 | Final Review |
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 |