U
U
UNy2021-07-15 15:17:28
Java
UNy, 2021-07-15 15:17:28

How does compare and swap work?

Explain in a simple way how compare and swap works? Let's say there is a variable that both stream1 and stream2 want to increment. Suppose thread1 entered earlier, do I understand correctly that thread2 can take the expected value while reading the variable by thread1, but before thread1 writes the new value?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Txao, 2021-07-15
@Txao

Read about the volatile keyword and cache coherence .

D
Developer, 2021-07-15
@samodum

read more about the race condition in addition to the advice of colleagues

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question