[concurrency-interest] On A Formal Definition of 'Data-Race'

Vitaly Davidovich 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:
> http://jsr166-concurrency.10961.n7.nabble.com/On-A-Formal-Definition-of-Data-Race-tp9408p9445.html
> Sent from the JSR166 Concurrency mailing list archive at Nabble.com.
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20130416/0ef226ab/attachment.html>

More information about the Concurrency-interest mailing list