c:c_threads:protected_access_to_shared_data_or_shared_resources
This is an old revision of the document!
C - C++ Threads - Protected access to shared data or shared resources
As threads can use several CPU-cores at once, access to common data structures to these threads have to be protected from concurrent access.
If locking is done too often the scalability is effectively limited to one core.
There are different methods that can be used for this protection:
- Mutex: The classical way would be to protect access to a variable by a mutex.
- Writelock / Readlock: Usually cheaper than mutexes.
- Atomic Read & Write: Since C++ 11. Also called lockless. Atomic is here to ensure no races are to be expected while accessing a variable.
c/c_threads/protected_access_to_shared_data_or_shared_resources.1623141934.txt.gz · Last modified: 2021/06/08 08:45 by peter