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

transient behavior in case object self-equality #5038

Closed
scabug opened this issue Sep 28, 2011 · 3 comments
Closed

transient behavior in case object self-equality #5038

scabug opened this issue Sep 28, 2011 · 3 comments
Assignees

Comments

@scabug
Copy link

scabug commented Sep 28, 2011

When running the following code, the first Ok == Ok check is sometimes false (maybe 3 out of 10), the following ones are true as expected.

package bug

import collection.mutable.ListBuffer
import actors.{TIMEOUT, Actor}

class Work {

  sealed trait Result
  case object Ok extends Result

  val timer = new Actor {
    private var results = new ListBuffer[Result]

    def act() {
      loop {
        react {
          case r: Result =>
            results += r
          case 'tick =>
            println(results(0)+", "+results(1))
            println("compare: "+(results(0) == results(1)))
            results.clear()
          case 'stop =>
            exit()
        }
      }
    }
  }

  class CalcActor(id: Int) extends Actor {
    def act(): Unit = {
      timer ! Ok
      react { case x => reply(x); exit() }
    }
  }

  def doit() {
    timer.start()
    for (i <- 1 to 5) {
      val actors = for (i <- 1 to 2) yield new CalcActor(i).start()
      actors foreach { _ !? 'stop }
      timer ! 'tick
    }
    timer ! 'stop
  }

}

object Main {
  def main(args: Array[String]) {
    new Work().doit()
  }
}

Scala 2.9.1 does not seem to reproduce this behavior, however I post it since I couldn't find a clearly related issue, and since I don't know if the bug is fixed in 2.9.1 or just hidden by a changed timing condition.

Notes

  • while my 2.8.1 does not reproduce SI-4565, if I move the Response trait and Ok to the top-level out of Work class, everything seems to be fine
  • running the CalcActors serially also fixes the problem
@scabug
Copy link
Author

scabug commented Sep 28, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5038?orig=1
Reporter: Robin Palotai (ron)
Affected Versions: 2.8.1

@scabug
Copy link
Author

scabug commented Sep 28, 2011

@paulp said:
The equals method for Ok is reference equality.

It is inordinately unlikely that there is a bug in reference equality. You have vars, mutable state, and actors doing something in this code; we don't have the resources to debug that sort of thing. If you want to reopen this, please try to define the issue more precisely.

@scabug scabug closed this as completed Sep 28, 2011
@scabug
Copy link
Author

scabug commented Sep 28, 2011

Robin Palotai (ron) said:
Ok. I succeeded with a stripped down version, but then I noticed that in Scala 2.8.2 and 2.9.1 the discovered race condition is already fixed (the object constructor needed synchronization for storing the singleton).

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