Is there any class exists in boost or std STL, which takes advantages of atomic instructions and implements the synchronization locks which runs only in user space? I am sure that thread will spin continuously to acquire lock with such implementation, but that is fine with my use case. one of such sample implementation is here . But this is very simple lock allows only one reader or one writer. I am expecting lock implementation with either single writer or multiple readers should be allowed.
Asked
Active
Viewed 193 times
0
-
Take a look at this http://stackoverflow.com/questions/989795/example-for-boost-shared-mutex-multiple-reads-one-write – Pooja Nilangekar Aug 31 '15 at 07:46
-
You can easily implement a spin lock using [std:.atomic_flag](http://en.cppreference.com/w/cpp/atomic/atomic_flag) – Bo Persson Aug 31 '15 at 08:35
-
@PoojaNilangekar: I think shared_mutex or mutex will cause context switch to kernel if lock is not acquired. I do not want to get switched to kernel mode because of its cost and thread is preempted from execution. Main reason behind using user space locks. thanks for reply – rahul.deshmukhpatil Aug 31 '15 at 08:41
-
@BoPersson: Yes, In the end I will be using atomic instructions/variables only. But just want to know if there exists any standard class, which does all the things I mentioned. thanks for reply. – rahul.deshmukhpatil Aug 31 '15 at 08:43
-
@rahul.deshmukhpatil - If you look at the example, std::atomic_flag just needs a while-loop and a call to clear(). There is no standard class doing that, but you could easily create one if you want it to be more RAII-like. – Bo Persson Aug 31 '15 at 08:46
-
@BoPersson: Thanks, Now I will come up with mine own class for same. I am sure that this will cause locking in the cache lines but could bear that cost. – rahul.deshmukhpatil Aug 31 '15 at 08:49