4

How to implement a spinlock / event / semaphore

 3 years ago
source link: https://vorbrodt.blog/2021/04/29/how-to-implement-a-spinlock-event-semaphore/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to implement a spinlock / event / semaphore

Multi-threading has been the theme of my previous two classes where I discussed thread-pools and producer-consumer queues. Let’s talk about the fundamental aspects of multi-threading and some of its most basic building blocks: spinlocks, automatic and manual events, and semaphores.
In this week’s class I will show you how to implement these building blocks using only standard C++ components: std::atomic_flag, std::mutex, std::condition_variable.


Code from the class:
lesson_spinlock_event_semaphore_how_to.cpp
Complete implementation:
mutex.hpp | event.hpp | semaphore.hpp


Like this:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK