Questions tagged [atomicreference]

Java atomic.AtomicReference. (Use [stdatomic] for questions about C++20 std::atomic_ref)

Java

java.util.concurrent.atomic.AtomicReference<V> was new in Java 1.5

https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/atomic/AtomicReference.html

C++ - use for C++ atomic_ref<T>

std::atomic_ref<T> was new in C++20, allowing atomic ops on properly-aligned plain objects. Such as alignas(std::atomic_ref<long>::required_alignment) long foo;

https://en.cppreference.com/w/cpp/atomic/atomic_ref

55 questions
0
votes
1 answer

A thread-safe holder for arbitrary cloneable data

I have a class SomeMutableData with a public clone() method. I want to make sure, that no thread ever sees an inconsistent state (assuming the instances will be passed around using the holder only). I assume using synchronization is the safest…
maaartinus
  • 44,714
  • 32
  • 161
  • 320
0
votes
0 answers

Hazelcast IAtomicReference.alter lambda

I am trying to populate another atomic reference based on existing cache. I want to use lambdas for code simplicity (less boiler code required) but it doesn't seem to be working. This works: class PutFunction implements…
Pilo
  • 15
  • 3
0
votes
1 answer

Convert synchronized methods to non-blocking algorithm

Just find some information about non-blocking algorithms, so want to use them in practice. I changed some code from synchronized to non-blocking, so I want to ask does I made everything right and saved previous functionality. synchronized…
Edgar
  • 1,120
  • 4
  • 28
  • 53
0
votes
1 answer

Java AtomicReferenceFieldUpdater - ClassCastException when using generic types

I get the following error : Exception in thread "main" java.lang.ClassCastException at java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.(AtomicReferenceFieldUpdater.java:336) at…
FaNaJ
  • 1,329
  • 1
  • 16
  • 39
0
votes
0 answers

Atomic Reference Not Changing

My Atomic Reference is not changing when the user inputs an expression of numbers. I think it has something to do with the lines inside of my Verify button event handler at card1.CardValue() == (int)expInput.get(0) but I'm not sure how to fix this.…
John Doe
  • 107
  • 1
  • 8
0
votes
2 answers

C# how to protect the field of an atomic class?

I'm trying to make an AtomicReference class in C# and I want to keep the field reference protected, but I also need to return the value in the get method: class AtomicReference { private Object _value; public AtomicReference() { …
Kiril
  • 39,672
  • 31
  • 167
  • 226
0
votes
2 answers

AtomicReference

I got some questions about AtomicReference.compareAndSet() method, according to the doc, it said: Atomically sets the value to the given updated value if the current value == the expected value. As far as I understand, the == operator is comparing…
Arrow Cen
  • 733
  • 1
  • 8
  • 22
-1
votes
2 answers

Does the value of AtomicReference will be set lazily if we assign a function to it which returns some array?

I have this piece of code: AtomicReference> atomicStrings = new AtomicReference<>(); atomicStrings.set(someFunc()); Thread.sleep(10000); System.out.print(String.join(",", atomicStrings.get()); // will this print a,b,c ? Where private…
Rafay
  • 92
  • 8
-1
votes
2 answers

How AtomicReference use CAS in case of Complex Object

AtomicReference instance uses Unsafe CAS operation to leverage processor instructions for locking. But I am little bit confused how it works in case of complex object. For example let us assume that I have an instance of Person class (id, firstName,…
Shashi Shankar
  • 859
  • 2
  • 8
  • 25
-1
votes
2 answers

How to prevents read from happening whenever I am doing a write?

I am trying to implement lock by which I don't want to have reads from happening whenever I am doing a write. Below is my ClientData class in which I am using CountDownLatch - public class ClientData { private static final…
AKIWEB
  • 19,008
  • 67
  • 180
  • 294
1 2 3
4