Primitives in C++ for Multithreading
Motivation: There are some explanations on certain terminologies commonly seen whenever multithreading is brought up. These terminologies should be somewhat familiar to people who study computer science. However, even when I knew what they meant, I didn’t know how they interoperate with other “CS thingies”. For example, when one of my professor asked a question “If a computer just runs one thread at a time, is it necessary to ensure synchronization ?”, it befuddled me. I wondered if the question made any sense and why were we asked such a question. I also failed to understand how mutexes, locks, semaphores,etc were differ from each other and what does each of them bring to the table. This may make some sense to other people but it just challenged my understanding of multithreading and concurrent programming. One method to solidify our thoughts is to write about it. Hence this article. This article won’t provide with implementation details on each primitive. It is to throw light on when and where each primitive is useful, and not examples on how to write them in code. Understanding the above question opens up many aspects of concurrent programming. Here we will approach the synchronization primitives made available to use in the STL (C++ 20 and above). ...