Answer by Bill the Lizard for Memory ordering when using atomic variable
No, a is guaranteed to be set to true before b. When the values are read it is possible for them to both be true, both be false, or a to be true and b to be false.
View ArticleAnswer by Gray for Memory ordering when using atomic variable
is it possible for Thread B to print true and false?No it is not. If b gets set to true then a would have already been set to true and since AtomicBoolean wraps a volatile, both fields will be updated...
View ArticleMemory ordering when using atomic variable
AtomicBoolean a = new AtomicBoolean(false);AtomicBoolean b = new AtomicBoolean(false);Thread A { a.compareAndSet(false, true); b.compareAndSet(false, true);}Thread B { print b.get() print a.get()}From...
View Article
More Pages to Explore .....