Quantcast
Channel: Using compareAndSet for Thread safety - Stack Overflow
Browsing latest articles
Browse All 3 View Live

Answer by SimonJ for Using compareAndSet for Thread safety

compareAndSet() returns true if the current value equals the expected value v, and thus the value was updated to v + 1.In your first version, if both threads get the same initial value then one will...

View Article



Answer by NPE for Using compareAndSet for Thread safety

Define "work".Let's say value is initially zero. If the first function is called 100 times it would return each number between 1 and 100 exactly once. The second function doesn't have this...

View Article

Using compareAndSet for Thread safety

How is the following demo code thread-safe? We are ensuring whether the value is not modified in CAS instruction and then doing an increment on int. Doesn't return v + 1; step beat the whole purpose as...

View Article
Browsing latest articles
Browse All 3 View Live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>