Posts

Showing posts from April 27, 2017

C++: Thread-safe std::map with the speed of lock-free map

Image
Introduction:  Examples of use and testing of a thread-safe pointer and contention-free shared-mutex.  In this article we will show additional optimizations, examples of use and testing of a thread-safe pointer developed by us with an optimized shared mutex  contfree_safe_ptr<T>  - this is equivalent to  safe_ptr<T, contention_free_shared_mutex<>> In the end, we will show the comparative graphs of our thread-safe-pointer tests and some of the best lock-free algorithms from libCDS on Intel Core i5 / i7, Xeon, 2 x Xeon processors. You can find libCDS by the link:  https://github.com/khizmax/libcds In all benchmarks in this article used this commit of libCDS   https://github.com/khizmax/libcds/tree/5e2a9854b0a8625183818eb8ad91e5511fed5898 Read full  article :   https://www.codeproject.com/Articles/1183446/Thread-safe-std-map-with-the-speed-of-lock-free-ma Three related articles:   1....

C++: We make a std::shared_mutex 10 times faster

Image
Introduction:  High performance of lock-based data structures.  In this article, we will detail the atomic operations and C++11 memory barriers and the assembler instructions generated by it on x86_64 CPUs. Next, we’ll show how to speed up the work of  contfree_safe_ptr<std::map>  up to the level of complex and optimized lock-free data structures that are similar to  std::map<>  in terms of their functionality, for example:  SkipListMap  and  BronsonAVLTreeMap  from libCDS library (Concurrent Data Structures library):  https://github.com/khizmax/libcds And we can get such multi-threaded performance for any of your initially non-thread-safe T-class used as  contfree_safe_ptr<T>   –  it is   safe_ptr<T, contention_free_shared_mutex>   class, where  contention_free_shared_mutex   is own optimized shared-mutex. Namely, we will show how to realize your own ...

C++: We make any object thread-safe

Introduction:  Smart pointer that makes any object thread-safe for any operations, with the performance equal to that of optimized lock-free containers. In these 3 articles I’ll tell in detail about atomic operations, memory barriers and the rapid exchange of data between threads, as well as about the “sequence-points” by the example of “execute-around-idiom”. At the same time, we will try to do something useful together. There are no thread-safe containers (array, list, map ...) in the standard C++ library, which could be used in multiple threads without additional locks. In case of usage of standard containers for multithreading exchange, there is a danger for you to forget to protect one of the code sections with mutex or by mistake to protect it with another mutex. Obviously, a developer will make more mistakes if he/she uses his/her own solution instead of a standard one. And if the task is so complex that there is no any standard solution, then the developer, wh...