#2611 Spurious InterruptErr

SlimerDude Sun 18 Jun

I noticed that a spurious InterruptedErr is thrown if an Actor kills the pool it is in, and then calls Future.get():

using concurrent

class Interrupt {
    Void main() {
        pool1  := ActorPool()
        pool2  := ActorPool()

        actor1 := Actor(pool1) |->| {
            echo("Do cleanup stuff")
        }

        actor2 := Actor(pool2) |->| {
            try {
                pool2.kill              // interrupt all other actors in same pool
                actor1.send(null).get   // get() throws sys::InterruptedErr
                
            } catch (Err e)
                e.trace
        }
        
        actor2.send(null)       

        Actor.sleep(1sec)   // wait for errs to be logged
    }
}

Do cleanup stuff
sys::InterruptedErr: java.lang.InterruptedException
  java.lang.Object.wait (Object.java)
  java.lang.Object.wait (Object.java:485)
  concurrent::Future.get (Future.java:88)
  concurrent::Future.get (Future.java:75)
  acme::Interrupt.main (Interrupt.fan:16)
  fan.sys.Func$Indirect0.call (Func.java:128)
  concurrent::Actor.receive (Actor.java:101)
  concurrent::Actor._dispatch (Actor.java:230)
  concurrent::Actor._work (Actor.java:201)
  concurrent::ThreadPool$Worker.run (ThreadPool.java:262)

I hope the fix would something as simple as clearing the Java Thread's interrupted flag before wait() is called.

Login or Signup to reply.