This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Threading: Mechanisms for multi-threaded communication, which can refer to Go's chan or Node.js's postMessage. #2952
Labels
You can continue the conversation there. Go to discussion →
Multi-threaded communication is a series of mechanisms:
Mutex vs CAS Int
We only consider the comparison between locks and CAS, that is, the case of int increment.
trunk/research/lockless/mutex-int.cpp
: Use Mutex, int increment.trunk/research/lockless/lockless-int.cpp
: Use CAS, int increment.First, look at single-threaded, so that waiting and conflict can be eliminated, data is as follows:
Then, it's double-threaded, at this time Mutex or CAS must be used, no synchronization will cause data abnormalities and can only be used as a reference, data is as follows:
Next, test 3 threads, data is as follows:
Mutex vs CAS Queue
Consider the circular queue.
trunk/research/lockless/mutex-queue.cpp
: Use Mutex.trunk/research/lockless/lockless-queue.cpp
: Use CAS.Data is as follows:
The text was updated successfully, but these errors were encountered: