This repository has two objectives:
- Demonstrate the concepts of multiple threading/concurrency through code samples.
- Demonstrate the C++ multi-threading concepts through code samples.
- A simple usage of threads: threads.cpp
- Collecting return values from threads: return_from_function.cpp
- Data race occurs when two or more threads are trying to manipulate same shared data at the same time: data_race.cpp
- Different types of locking mechanisms: locking.cpp
- Counters should work regardless of how many threads are accessing it. See thread_safe_counters.cpp
- Check if a function completes within stipulated time or not: timeouts.cpp
- Syncing cameras to take pictures simultaneously:
- What are deadlocks and how do they happen? deadlock.cpp
- Consumer producer pattern for threads
- Using threadpool to avoid creating threads
- Trying to join a detached thread or thread that has already been joined. Under uncertainty, use thread member "joinable" to check if thread can be joined or not.
- Trying to acquire a mutex twice.
- Everything is passed by value. Use std::ref to pass argument by reference.
- Unlocked shared data members cause data race if their value is manipulated by threads.
- When using mutex::lock() and mutex::unlock(), forgetting to unlock will cause the resource to not be released.