[concurrency-interest] On A Formal Definition of 'Data-Race'
vitalyd at gmail.com
Tue Apr 16 15:22:49 EDT 2013
String caches the hashcode in a plain field; multiple threads can race to
compute and store the hashcode, but since string is immutable, this is
fine. The code is careful to operate only on a local variable to avoid
re-reads of the field (which could theoretically lead to wrong results if,
e.g., JIT reordered code in a certain way).
On Apr 16, 2013 3:12 PM, "thurstonn" <thurston at nomagicsoftware.com> wrote:
> Just curious, how is String#hashCode() racy?
> Strings are immutable in java; I looked at the code a bit and I didn't see
> anything that looked racy.
> The only thing I guess could be:
> private char value
> Although that array is never modified in the String class, so . . .
> View this message in context:
> Sent from the JSR166 Concurrency mailing list archive at Nabble.com.
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Concurrency-interest