Semantics of Asynchronous Exceptions

Conventions and Notations
 Primitive IO actions are considered “values” for the purely functional part of the semantics (>>=, putChar, block etc)  Evaluation contexts are assumed to be maximal
• F = [.] | F >>= M | catch F H • E = F | F [ block E ] | F [ unblock E ]

 Threads can be:
• Stuck: ( … )• • Runnable: ( … )o

© 2010 Galois, Inc. All rights reserved.

IO Primitives

© 2010 Galois, Inc. All rights reserved.

Threads and Exceptions

© 2010 Galois, Inc. All rights reserved.

Basic Transitions

© 2010 Galois, Inc. All rights reserved.

Asynchronous Exceptions

© 2010 Galois, Inc. All rights reserved.

New / Replacement Rules
 {E1 [ throwTo t e ]} bs | {E2 [ unblock F [ M ] ] } ct  {E1 [ return () ]} os | {E2 [ unblock F [ throw e ]] } ot  {E1 [ throwTo t e ]} bs | {E2 [ M ] } •t  {E1 [ return () ]} os | {E2 [ throw e ] }ot  {E [ throwTo t e ]} bs  {E [ throwTo t e ]} •s  {E [ throwTo t e ]} bs
(n th a t) o re d

 {E [ return () ]} os

 {E [ throwTo s e ]} bs  {E [ throw e ]} os

© 2010 Galois, Inc. All rights reserved.

Higher-level Operators
 onException :: IO a -> IO b -> IO a onException io what = io `catch` (\e -> what >> throw (e :: SomeException))  finally :: IO a -> IO b -> IO a a `finally` sequel = block $ do r <- unblock a `onException` sequel sequel return r  try :: Exception e => IO a -> IO (Either e a) try a = (a >>= (return . Right)) `catch` (return . Left)

© 2010 Galois, Inc. All rights reserved.

Sign up to vote on this title
UsefulNot useful