You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Multi-threaded communication is a series of mechanisms:
First is the efficient communication queue.
Then there is the mechanism for communication between threads.
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:
Number of threads
Synchronization
Number of loops
Actual number of loops
Time consumed
Single thread
None
300M
300M
646ms
Single thread
Mutex
300M
300M
5373ms
Single thread
CAS
300M
300M
1911ms
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:
Number of threads
Synchronization
Number of loops
Actual number of loops
Time consumed
2 threads
None
60M
65M
468ms
2 threads
Mutex
60M
120M
5009ms
2 threads
CAS
60M
120M
3295ms
Note: The actual number of loops should be 120M, because there are 2 threads, each with 60M.
Next, test 3 threads, data is as follows:
Number of threads
Synchronization
Number of loops
Actual number of loops
Time consumed
3 threads
None
50M
60M
677ms
3 threads
Mutex
50M
150M
7909ms
3 threads
CAS
50M
150M
4317ms
Mutex vs CAS Queue
Consider the circular queue.
trunk/research/lockless/mutex-queue.cpp: Use Mutex.
trunk/research/lockless/lockless-queue.cpp: Use CAS.
FeatureIt's a new feature.EnglishNativeThis issue is conveyed exclusively in English.
1 participant
Converted from issue
This discussion was converted from issue #2952 on July 18, 2023 02:58.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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:
Beta Was this translation helpful? Give feedback.
All reactions