Permalink
Browse files

Close small race condition when registering monitor

  • Loading branch information...
Robert Newson
Robert Newson committed Nov 6, 2012
1 parent e2bf4e3 commit 77b46daf44ff1e810c755aba4bb1e26b28635cf0
Showing with 11 additions and 4 deletions.
  1. +11 −4 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
}

0 comments on commit 77b46da

Please sign in to comment.