The purpose and design guidelines of concurrent data structures to understand and learn

Purpose of concurrent data structures:

1. The concurrent data structure is designed to allow multiple threads to access concurrently, and the threads can perform the same or different operations on the data structure .

2. In a multi-threaded environment, there is no data loss or damage , and all data needs to be maintained as it is, and the data structure of unconditional competition;

3. It is necessary to provide threads with the opportunity to access the data structure concurrently; in essence, only one thread can acquire the lock at the same time under the protection of the mutex. In order to protect data, mutex will explicitly prevent threads from concurrently accessing data structures; ( mutual exclusion can sometimes lead to serial results )

4. Serialization means that threads access data in turn and perform serial access to data.

5. It is necessary to carefully consider the data structure to ensure real concurrency. Reduce the protection area and reduce the serialization operation ;


Design Guidelines for Concurrent Data Structures

1. The operation is performed within the scope of the lock, whether it can be performed outside the lock; ( principle of reducing the protection area )

2. Whether different mutexes in the data structure can protect different areas; ( correctness, no data loss or damage principle )

3. Whether all operations need the same level of mutex protection; ( Subdividing the mutex protection and reducing the protection area principle )

4. Can simple modifications be made to the data structure to increase the probability of concurrent access; ( reduce the principle of serialization operation )

reference:

1、《C+±Concurrency-In-Action-2ed》

Guess you like

Origin blog.csdn.net/KPer_Yang/article/details/130163537