Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6557171

Warn that ++ is not atomic (on longs?)

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Unresolved
    • P4
    • None
    • 6
    • tools
    • generic
    • generic

    Description

      From email:

      Here's another warning the compiler could give. For the
      second time in a week, I've seen code like:

           public Random() { this(++seedUniquifier ....); }
           private static volatile long seedUniquifier = 8682522807148012L;

      where it looks like people think that declaring seedUniquifier
      to be volatile means that ++seedUniquifier will work like an
      atomic operation. I know it doesn't, and you know it doesn't,
      but "people" seem to think it does, hence the need for the
      warning. You might get a lot of false positives, though, like
      this one in java.util.Random, where the ++ doesn't *have* to
      be atomic.

      Attachments

        Activity

          People

            mcimadamore Maurizio Cimadamore
            ahe Peter Ahe
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Imported:
              Indexed: