Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing @volatile declaration on a field in class Enumeration #5571

Closed
scabug opened this issue Mar 14, 2012 · 2 comments
Closed

Missing @volatile declaration on a field in class Enumeration #5571

scabug opened this issue Mar 14, 2012 · 2 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Mar 14, 2012

Class Enumeration defines method values which returns the values of an enumeration as a set.
This method computes this set lazily and is defined as follows:

/** The cache listing all values of this enumeration. */
@transient private var vset: ValueSet = null
@transient private var vsetDefined = false

def values: ValueSet = {
  if (!vsetDefined) {
    vset = new ValueSet(immutable.SortedSet.empty[Int] ++ (vmap.values map (_.id)))
    vsetDefined = true
  }
  vset
}

I claim, that the field vsetDefined has to be declared @volatile, otherwise a thread invoking values might see vsetDefined as true, but may not see the actual value in field vset, i.e. may see vset still to be null. If vsetDefined were declared @volatile, a happens-before relation would be established between writing field vset and reading it.

@scabug
Copy link
Author

scabug commented Mar 14, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5571?orig=1
Reporter: @dgruntz
Affected Versions: 2.9.1
Other Milestones: 2.10.0

@scabug
Copy link
Author

scabug commented Apr 10, 2012

@paulp said:
Thanks: af4e0f0991

@scabug scabug closed this as completed Apr 10, 2012
@scabug scabug added this to the 2.10.0-M2 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants