Go

How to design and implement a thread-safe Map data structure

Map is a very common data structure used to store some unordered key-value pairs. In mainstream programming languages, it comes with its implementation by default. STL in C and C++ implements Map, JavaScript also has Map, Java has HashMap, Swift and Python have Dictionary, Go has Map, and Objective-C has NSDictionary and NSMutableDictionary. Are all the above maps thread-safe? The answer is no, not all thread-safe. How can a thread-safe Map be implemented? To answer this question, you need to start with how to implement a Map.