[concurrency-interest] Is Reference.reachabilityFence() needed in Reference constructor?

thurstonn thurston at nomagicsoftware.com
Thu Oct 22 11:30:04 EDT 2015


Well, you learn something new every day.

I wrote some simple tests to confirm Aleksey's claim, and they do.

In fact, Peter's original code could be modified to an even more surprising:


Object obj = new Object();
WeakReference<?> wr = new WeakReference(obj)

. . .
assert null != wr.get() : "This can fail"

I might suggest that the doc for  reference package
<http://docs.oracle.com/javase/8/docs/api/java/lang/ref/package-summary.html>  
is not ideal:

"An object is strongly reachable if it can be reached by some thread without
traversing any reference objects. *A newly-created object is strongly
reachable by the thread that created it.*"

Depending on how you parse it, it may not be wrong, but is misleading 



--
View this message in context: http://jsr166-concurrency.10961.n7.nabble.com/Is-Reference-reachabilityFence-needed-in-Reference-constructor-tp12819p12840.html
Sent from the JSR166 Concurrency mailing list archive at Nabble.com.


More information about the Concurrency-interest mailing list