Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Close small race condition when registering monitor

  • Loading branch information...
commit 77b46daf44ff1e810c755aba4bb1e26b28635cf0 1 parent e2bf4e3
@rnewson authored
Showing with 11 additions and 4 deletions.
  1. +11 −4 src/main/scala/scalang/node/ProcessAdapter.scala
View
15 src/main/scala/scalang/node/ProcessAdapter.scala
@@ -95,7 +95,7 @@ abstract class ProcessHolder(ctx : ProcessContext) extends ProcessAdapter {
}
trait ProcessAdapter extends ExitListenable with SendListenable with LinkListenable with MonitorListenable with Instrumented with Logging {
- @volatile var state = 'alive
+ var state = 'alive
def self : Pid
def fiber : Fiber
def referenceCounter : ReferenceCounter
@@ -109,8 +109,10 @@ trait ProcessAdapter extends ExitListenable with SendListenable with LinkListena
def handleMonitorExit(monitored : Any, ref : Reference, reason : Any)
def exit(reason : Any) {
- if (state != 'alive) return
- state = 'dead
+ synchronized {
+ if (state != 'alive) return
+ state = 'dead
+ }
// Exit listeners first, so that process is removed from table.
for(e <- exitListeners) {
@@ -165,7 +167,12 @@ trait ProcessAdapter extends ExitListenable with SendListenable with LinkListena
for (listener <- monitorListeners) {
m.addMonitorListener(listener)
}
- monitors.put(m.ref, m)
+ synchronized {
+ if (state != 'alive)
+ m.monitorExit('noproc)
+ else
+ monitors.put(m.ref, m)
+ }
m
}
Please sign in to comment.
Something went wrong with that request. Please try again.