I want to write some library in C++11, which will be used in C and C++ programs (so all exported function will be marked as extern "C").
I want all exported functions to be thread-safe. So if I would write this library on windows, I can use Critical Section Objects, but what should I use in Linux?
Here's my options:
- POSIX mutexes
- C++11 std::mutex
- C++11 atomic variables
- Linux (POSIX) semaphores
Troubles: There is no guarantees of which thread - POSIX or C++11 - will be used in code which will use my library.
So 1) and 2) options cannot be used, because POSIX threads != C++11 threads.
Rest options look much slower than mutex-based solutions.
Does anybody know the correct way to create thread-safe library on Linux?
Aucun commentaire:
Enregistrer un commentaire