Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
A thread is the smallest unit of processing that can be scheduled by an operating system' [1].
std::thread is the C++11 thread class.
thread (general) design
As a personal note, I will put my thread design questions here. Feel free to contact me
if you can provide answers with references.
- To make a class thread-safe, is it enough to add a mutex at the start of each method?
- In a thread-safe-to-be class, which return types can a methods have? Can it be a pointer, const pointer, shared_ptr, weak_ptr, reference, std::vector, std::vector reference, etc? And what about std::atomic?
- In a thread-safe-to-be class, which methods (depending on arguments, return type, work done inside of the method) can be without mutexes?
- When adding a mutex to a class method, I tend to suggest always to use std::recursive_mutex, instead of the std::mutex, because std::recursive_mutex is as safe as a std::mutex, but more flexible. When is std::mutex to be preferred?
- When adding a mutex to a class method, I tend to refrain from using timed mutex, as I feel these are sloppy. When would using timed mutexes be recommended?
- When benchmarking a class for thread-safety, is it enough to create simply create multiple threads reading and writing to all methods of the class? That, if this works, the class can be called thread-safe?
- When having benchmarking a class for thread-safety in the way above, when to use tools like helgrind?
External links
- Wikipedia page about threads
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.
