jeudi 4 février 2021

Counting semaphore in C++11 without using condtion_variable

I understand that semaphores are not available in C++11. Trying search for semaphores in C++11, I stumble on proposals of implementing a Semaphore using a condition_variable like this one.

C++0x has no semaphores? How to synchronize threads?
https://riptutorial.com/cplusplus/example/30142/semaphore-cplusplus-11

Question:
Is it possible to implement a "Counting Semaphore" in C++11 without using std::condition_variable? I mean some way of implementing an std::queue with an std::mutex which provides a timed wait functionality?

The reason of avoiding condition_variables is that it does not use a steady clock and it has issues with spurious interrupts on various platforms.

Context:
I have multiple threads (close to 20) "waiting with a timeout" for a shared resource.

Aucun commentaire:

Enregistrer un commentaire