Upgrade to Pro — share decks privately, control downloads, hide ads and more …

High-Level Concurrency Libraries: Challenges for Tool Support

Philipp Haller
October 27, 2015
130

High-Level Concurrency Libraries: Challenges for Tool Support

Philipp Haller

October 27, 2015
Tweet

Transcript

  1. High-Level Concurrency Libraries:
    Challenges for Tools
    Philipp Haller!
    KTH Royal Institute of Technology!
    Sweden!
    !
    Eclipse Technology eXchange (ETX)!
    SPLASH, Pittsburgh, PA, USA, October 2015
    1

    View full-size slide

  2. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Context
    • 2005–2015: author or co-author of a variety of
    concurrency libraries for Scala!
    • Some in wide industrial use, some experimental!
    • Common theme: how expressive are pure library
    approaches?!
    • High-level concurrency libraries ~= embedded
    domain-specific languages
    2

    View full-size slide

  3. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Disclaimers
    • Disclaimer 1: I am not an IDE expert!
    • A lot of work I am not aware of!
    • Disclaimer 2: my observations are biased toward
    certain languages and runtimes!
    • Statically-typed languages like Scala or Java!
    • Managed runtime environments à la JVM
    3

    View full-size slide

  4. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Experience
    • Developed libraries:!
    • Scala Actors (2006)!
    • Scala Joins (2008)!
    • Scala Futures (2012)!
    • FlowPools (2012)!
    • Scala Async (2013)!
    • Exploration of Scala as a growable language
    4

    View full-size slide

  5. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Experience
    • Developed libraries:!
    • Scala Actors (2006)!
    • Scala Joins (2008)!
    • Scala Futures (2012)!
    • FlowPools (2012)!
    • Scala Async (2013)!
    • Exploration of Scala as a growable language
    4
    Macro library

    View full-size slide

  6. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Experience
    • Developed libraries:!
    • Scala Actors (2006)!
    • Scala Joins (2008)!
    • Scala Futures (2012)!
    • FlowPools (2012)!
    • Scala Async (2013)!
    • Exploration of Scala as a growable language
    4
    Macro library
    Production use
    at Twitter, The Guardian
    and others

    View full-size slide

  7. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Experience
    • Developed libraries:!
    • Scala Actors (2006)!
    • Scala Joins (2008)!
    • Scala Futures (2012)!
    • FlowPools (2012)!
    • Scala Async (2013)!
    • Exploration of Scala as a growable language
    4
    Macro library
    Production use
    at Twitter, The Guardian
    and others
    Production use
    at LinkedIn, Gilt Groupe
    and others

    View full-size slide

  8. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Experience
    • Developed libraries:!
    • Scala Actors (2006)!
    • Scala Joins (2008)!
    • Scala Futures (2012)!
    • FlowPools (2012)!
    • Scala Async (2013)!
    • Exploration of Scala as a growable language
    4
    Production use
    at Twitter, The Guardian
    and others
    Production use
    at LinkedIn, Gilt Groupe
    and others
    Production use
    at Morgan Stanley,
    Gawker and others

    View full-size slide

  9. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Experience
    • Developed libraries:!
    • Scala Actors (2006)!
    • Scala Joins (2008)!
    • Scala Futures (2012)!
    • FlowPools (2012)!
    • Scala Async (2013)!
    • Exploration of Scala as a growable language
    4
    Guy Steele. “Growing a Language.” OOPSLA ’98
    Production use
    at Twitter, The Guardian
    and others
    Production use
    at LinkedIn, Gilt Groupe
    and others
    Production use
    at Morgan Stanley,
    Gawker and others

    View full-size slide

  10. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Why Growable Languages
    for Concurrency?
    • Actors, agents, communicating event-loops!
    • CML!
    • Futures, promises!
    • Async/await, async-finish!
    • Reactive Extensions (Rx)!
    • Join-calculus!
    • STM!
    • …
    5

    View full-size slide

  11. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Why Growable Languages
    for Concurrency?
    • Actors, agents, communicating event-loops!
    • CML!
    • Futures, promises!
    • Async/await, async-finish!
    • Reactive Extensions (Rx)!
    • Join-calculus!
    • STM!
    • …
    5
    Which one is going to “win”?

    View full-size slide

  12. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Why Growable Languages
    for Concurrency? (cont’d)
    Enables multiple high-level libraries embedded in the
    same host language!
    • Richer programming system!
    • Enables reusing the compilers, debuggers, and
    IDEs of the host language
    6

    View full-size slide

  13. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Why Growable Languages
    for Concurrency? (cont’d)
    7

    View full-size slide

  14. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Why Growable Languages
    for Concurrency? (cont’d)
    Simplifies research
    7

    View full-size slide

  15. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Why Growable Languages
    for Concurrency? (cont’d)
    Simplifies research
    • Library extensions vs. language extensions
    7

    View full-size slide

  16. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Why Growable Languages
    for Concurrency? (cont’d)
    Simplifies research
    • Library extensions vs. language extensions
    • Performance comparisons between different
    libraries more meaningful
    7

    View full-size slide

  17. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Why Growable Languages
    for Concurrency? (cont’d)
    Simplifies research
    • Library extensions vs. language extensions
    • Performance comparisons between different
    libraries more meaningful
    • Experimental evaluation on real code
    7

    View full-size slide

  18. Challenges for
    Tools
    8

    View full-size slide

  19. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    New API Designs
    9

    View full-size slide

  20. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    New API Designs
    • Unique integration of features: Scala enables new
    API designs
    9

    View full-size slide

  21. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    New API Designs
    • Unique integration of features: Scala enables new
    API designs
    • Objects + functions, traits, path-dependent types
    9

    View full-size slide

  22. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    New API Designs
    • Unique integration of features: Scala enables new
    API designs
    • Objects + functions, traits, path-dependent types
    • Pattern matching, extractors
    9

    View full-size slide

  23. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    New API Designs
    • Unique integration of features: Scala enables new
    API designs
    • Objects + functions, traits, path-dependent types
    • Pattern matching, extractors
    • Implicits
    9

    View full-size slide

  24. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    New API Designs
    • Unique integration of features: Scala enables new
    API designs
    • Objects + functions, traits, path-dependent types
    • Pattern matching, extractors
    • Implicits
    • ...
    9

    View full-size slide

  25. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    New API Designs
    • Unique integration of features: Scala enables new
    API designs
    • Objects + functions, traits, path-dependent types
    • Pattern matching, extractors
    • Implicits
    • ...
    • Not all API designs well-supported by tools
    9

    View full-size slide

  26. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    New API Designs: Example
    10

    View full-size slide

  27. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    New API Designs: Example
    • Actors widely-used abstraction for concurrent
    programming in Scala
    10

    View full-size slide

  28. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    New API Designs: Example
    • Actors widely-used abstraction for concurrent
    programming in Scala
    • Actor = concurrent “process” that communicates via
    asynchronous messages
    10

    View full-size slide

  29. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    New API Designs: Example
    • Actors widely-used abstraction for concurrent
    programming in Scala
    • Actor = concurrent “process” that communicates via
    asynchronous messages
    • Asynchronous send, event-based receive
    10

    View full-size slide

  30. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    New API Designs: Example
    • Actors widely-used abstraction for concurrent
    programming in Scala
    • Actor = concurrent “process” that communicates via
    asynchronous messages
    • Asynchronous send, event-based receive
    • Low-level data races easy to avoid (by convention)
    10

    View full-size slide

  31. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    New API Designs: Example
    • Actors widely-used abstraction for concurrent
    programming in Scala
    • Actor = concurrent “process” that communicates via
    asynchronous messages
    • Asynchronous send, event-based receive
    • Low-level data races easy to avoid (by convention)
    • Debugging high-level messaging protocols can be
    difficult
    10

    View full-size slide

  32. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Debugging Actor Programs
    11
    class TaskCoordinator extends Actor {
    !
    var worker: Option[ActorRef] = None
    !
    def receive = {
    case Start(workerRef) =>
    this.worker = Some(workerRef)
    !
    case Do(tasks) =>
    assert(worker.nonEmpty)
    !
    ..
    }
    !
    }

    View full-size slide

  33. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Debugging Actor Programs
    11
    class TaskCoordinator extends Actor {
    !
    var worker: Option[ActorRef] = None
    !
    def receive = {
    case Start(workerRef) =>
    this.worker = Some(workerRef)
    !
    case Do(tasks) =>
    assert(worker.nonEmpty)
    !
    ..
    }
    !
    }
    Fails if ‘Do’ sent
    without prior
    ‘Start’

    View full-size slide

  34. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Debugging Actor Programs
    11
    class TaskCoordinator extends Actor {
    !
    var worker: Option[ActorRef] = None
    !
    def receive = {
    case Start(workerRef) =>
    this.worker = Some(workerRef)
    !
    case Do(tasks) =>
    assert(worker.nonEmpty)
    !
    ..
    }
    !
    }
    Fails if ‘Do’ sent
    without prior
    ‘Start’
    “At what point
    was ‘Do’ message sent
    that caused assertion
    failure?”

    View full-size slide

  35. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Problem
    • In general, sender and receiver are executed by two
    different worker threads, on two different stacks!
    • Messages transferred using a concurrent queue
    of the receiver (its “mailbox”)!
    • Flow of control cannot be traced using traditional
    stack-based debuggers
    12

    View full-size slide

  36. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Solution: Stack Retention
    13

    View full-size slide

  37. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Solution: Stack Retention
    Idea:
    13

    View full-size slide

  38. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Solution: Stack Retention
    Idea:
    • At the point when a message is sent:
    13

    View full-size slide

  39. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Solution: Stack Retention
    Idea:
    • At the point when a message is sent:
    • Save the call stack as well as stack frame
    information (e.g., local variable values)
    13

    View full-size slide

  40. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Solution: Stack Retention
    Idea:
    • At the point when a message is sent:
    • Save the call stack as well as stack frame
    information (e.g., local variable values)
    • Attach the call stack to the sent message object
    13

    View full-size slide

  41. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Solution: Stack Retention
    Idea:
    • At the point when a message is sent:
    • Save the call stack as well as stack frame
    information (e.g., local variable values)
    • Attach the call stack to the sent message object
    • When a user-defined breakpoint is reached
    present the collected stack frames to the user (if
    they are relevant)
    13

    View full-size slide

  42. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Solution: Stack Retention
    Idea:
    • At the point when a message is sent:
    • Save the call stack as well as stack frame
    information (e.g., local variable values)
    • Attach the call stack to the sent message object
    • When a user-defined breakpoint is reached
    present the collected stack frames to the user (if
    they are relevant)
    13
    Iulian Dragos. “Stack Retention in Debuggers for
    Concurrent Programs.” Scala Workshop ’13

    View full-size slide

  43. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Futures
    • Stack retention also works for futures!
    • Call stack is saved whenever a future is created
    14
    val fut = Future {
    // concurrent computation
    }
    !
    val transformed = fut.map { x =>
    transform(x)
    }
    !
    transformed.onComplete {
    case Success(v) =>
    ..
    case Failure(t) =>
    ..
    }

    View full-size slide

  44. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Are We Done?
    15

    View full-size slide

  45. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Are We Done?
    • Actors and futures not the only concurrency
    abstractions that should be supported
    15

    View full-size slide

  46. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Are We Done?
    • Actors and futures not the only concurrency
    abstractions that should be supported
    • Streams, data-flow, join patterns, etc.
    15

    View full-size slide

  47. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Are We Done?
    • Actors and futures not the only concurrency
    abstractions that should be supported
    • Streams, data-flow, join patterns, etc.
    • Effort to implement support for a given concurrency
    abstraction is high:
    15

    View full-size slide

  48. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Are We Done?
    • Actors and futures not the only concurrency
    abstractions that should be supported
    • Streams, data-flow, join patterns, etc.
    • Effort to implement support for a given concurrency
    abstraction is high:
    • First release of Scala Actors: 2006
    15

    View full-size slide

  49. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Are We Done?
    • Actors and futures not the only concurrency
    abstractions that should be supported
    • Streams, data-flow, join patterns, etc.
    • Effort to implement support for a given concurrency
    abstraction is high:
    • First release of Scala Actors: 2006
    • First use of Scala Actors at Twitter: 2008
    15

    View full-size slide

  50. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Are We Done?
    • Actors and futures not the only concurrency
    abstractions that should be supported
    • Streams, data-flow, join patterns, etc.
    • Effort to implement support for a given concurrency
    abstraction is high:
    • First release of Scala Actors: 2006
    • First use of Scala Actors at Twitter: 2008
    • First release of Akka: 2009
    15

    View full-size slide

  51. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Are We Done?
    • Actors and futures not the only concurrency
    abstractions that should be supported
    • Streams, data-flow, join patterns, etc.
    • Effort to implement support for a given concurrency
    abstraction is high:
    • First release of Scala Actors: 2006
    • First use of Scala Actors at Twitter: 2008
    • First release of Akka: 2009
    • Iulian Dragos first presents Async debugger ideas: 2013
    15
    Iulian Dragos. “Stack Retention in Debuggers for
    Concurrent Programs.” Scala Workshop ’13

    View full-size slide

  52. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Are We Done?
    • Actors and futures not the only concurrency
    abstractions that should be supported
    • Streams, data-flow, join patterns, etc.
    • Effort to implement support for a given concurrency
    abstraction is high:
    • First release of Scala Actors: 2006
    • First use of Scala Actors at Twitter: 2008
    • First release of Akka: 2009
    • Iulian Dragos first presents Async debugger ideas: 2013
    • First release of Async debugger: 2015
    15
    Iulian Dragos. “Stack Retention in Debuggers for
    Concurrent Programs.” Scala Workshop ’13

    View full-size slide

  53. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Are We Done?
    • Actors and futures not the only concurrency
    abstractions that should be supported
    • Streams, data-flow, join patterns, etc.
    • Effort to implement support for a given concurrency
    abstraction is high:
    • First release of Scala Actors: 2006
    • First use of Scala Actors at Twitter: 2008
    • First release of Akka: 2009
    • Iulian Dragos first presents Async debugger ideas: 2013
    • First release of Async debugger: 2015
    15
    Iulian Dragos. “Stack Retention in Debuggers for
    Concurrent Programs.” Scala Workshop ’13
    9 years!

    View full-size slide

  54. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Issues
    16

    View full-size slide

  55. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Issues
    • Issue 1: Concurrency libraries often provide new
    control-flow abstractions
    16

    View full-size slide

  56. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Issues
    • Issue 1: Concurrency libraries often provide new
    control-flow abstractions
    • Issue 2: Development of tool support decoupled
    from library implementation
    16

    View full-size slide

  57. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Issues
    • Issue 1: Concurrency libraries often provide new
    control-flow abstractions
    • Issue 2: Development of tool support decoupled
    from library implementation
    • Issue 3: High development effort means dedicated
    tool support only implemented for few libraries
    16

    View full-size slide

  58. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Issue 1
    17

    View full-size slide

  59. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Issue 1
    • Concurrency libraries often provide new abstractions
    for managing concurrent control flow
    17

    View full-size slide

  60. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Issue 1
    • Concurrency libraries often provide new abstractions
    for managing concurrent control flow
    • Typically, control flow spans several threads
    17

    View full-size slide

  61. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Issue 1
    • Concurrency libraries often provide new abstractions
    for managing concurrent control flow
    • Typically, control flow spans several threads
    • Examples: actor multiplexing, future scheduling
    17

    View full-size slide

  62. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Issue 1
    • Concurrency libraries often provide new abstractions
    for managing concurrent control flow
    • Typically, control flow spans several threads
    • Examples: actor multiplexing, future scheduling
    • Control-flow abstractions not necessarily
    implemented in terms of abstractions known to tools
    17

    View full-size slide

  63. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Issue 1
    • Concurrency libraries often provide new abstractions
    for managing concurrent control flow
    • Typically, control flow spans several threads
    • Examples: actor multiplexing, future scheduling
    • Control-flow abstractions not necessarily
    implemented in terms of abstractions known to tools
    • Efficiency and scalability requirements usually
    preclude layering of abstractions
    17

    View full-size slide

  64. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Issue 1: Example
    • Library defines new control-flow abstractions!
    • Example: synchronous channel using a Joins library
    18

    View full-size slide

  65. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Issue 1: Example
    • Library defines new control-flow abstractions!
    • Example: synchronous channel using a Joins library
    18
    class SyncChannel extends Joins {
    object Read extends NullarySyncEvent[Int]
    object Write extends SyncEvent[Unit, Int]
    !
    join {
    case Read() & Write(x) =>
    Read reply x
    Write reply {}
    }
    }
    Philipp Haller and Tom Van Cutsem. “Implementing Joins
    using Extensible Pattern Matching.” Coordination ’08

    View full-size slide

  66. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Issue 1: Example
    • Library defines new control-flow abstractions!
    • Example: synchronous channel using a Joins library
    18
    class SyncChannel extends Joins {
    object Read extends NullarySyncEvent[Int]
    object Write extends SyncEvent[Unit, Int]
    !
    join {
    case Read() & Write(x) =>
    Read reply x
    Write reply {}
    }
    }
    Events not
    transferred using
    actors or futures
    Philipp Haller and Tom Van Cutsem. “Implementing Joins
    using Extensible Pattern Matching.” Coordination ’08

    View full-size slide

  67. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Issue 2
    Development of tool support decoupled from library
    implementation!
    • Library implementer most familiar with mechanics,
    but cannot support tools through implementation!
    • Tool developers have to reverse engineer library
    implementations
    19

    View full-size slide

  68. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Libraries with “Support for Tools”
    • Futures in Scala include usability features!
    • Little implementation effort makes big difference
    20

    View full-size slide

  69. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Libraries with “Support for Tools”
    • Futures in Scala include usability features!
    • Little implementation effort makes big difference
    20
    Welcome to Scala version 2.11.6 (Java HotSpot(TM) ..).
    Type in expressions to have them evaluated.
    Type :help for more information.
    !
    scala> import scala.concurrent._
    import scala.concurrent._
    !
    scala> val fut = Future { 40 + 2 }
    !
    !
    !
    !
    !

    View full-size slide

  70. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    :10: error: Cannot find an implicit ExecutionContext. You might pass
    Libraries with “Support for Tools”
    • Futures in Scala include usability features!
    • Little implementation effort makes big difference
    20
    Welcome to Scala version 2.11.6 (Java HotSpot(TM) ..).
    Type in expressions to have them evaluated.
    Type :help for more information.
    !
    scala> import scala.concurrent._
    import scala.concurrent._
    !
    scala> val fut = Future { 40 + 2 }
    !
    !
    !
    !
    !

    View full-size slide

  71. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    :10: error: Cannot find an implicit ExecutionContext. You might pass
    Libraries with “Support for Tools”
    • Futures in Scala include usability features!
    • Little implementation effort makes big difference
    20
    Welcome to Scala version 2.11.6 (Java HotSpot(TM) ..).
    Type in expressions to have them evaluated.
    Type :help for more information.
    !
    scala> import scala.concurrent._
    import scala.concurrent._
    !
    scala> val fut = Future { 40 + 2 }
    !
    !
    !
    !
    !
    ???

    View full-size slide

  72. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    :10: error: Cannot find an implicit ExecutionContext. You might pass
    Libraries with “Support for Tools”
    • Futures in Scala include usability features!
    • Little implementation effort makes big difference
    20
    Welcome to Scala version 2.11.6 (Java HotSpot(TM) ..).
    Type in expressions to have them evaluated.
    Type :help for more information.
    !
    scala> import scala.concurrent._
    import scala.concurrent._
    !
    scala> val fut = Future { 40 + 2 }
    !
    !
    !
    !
    !
    But…

    View full-size slide

  73. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    :10: error: Cannot find an implicit ExecutionContext. You might pass
    Libraries with “Support for Tools”
    • Futures in Scala include usability features!
    • Little implementation effort makes big difference
    20
    Welcome to Scala version 2.11.6 (Java HotSpot(TM) ..).
    Type in expressions to have them evaluated.
    Type :help for more information.
    !
    scala> import scala.concurrent._
    import scala.concurrent._
    !
    scala> val fut = Future { 40 + 2 }
    !
    !
    !
    !
    !
    an (implicit ec: ExecutionContext) parameter to your method
    or import scala.concurrent.ExecutionContext.Implicits.global.
    val fut = Future { 40 + 2 }
    ^
    But…

    View full-size slide

  74. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Creating Futures
    21
    val fut = Future { .. }
    // equivalent to:
    val fut = Future.apply({ .. })

    View full-size slide

  75. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Creating Futures
    21
    object Future {
    !
    /** Starts an asynchronous computation and returns a `Future` object..
    *
    * @tparam T the type of the result
    * @param body the asynchronous computation
    * @param executor the execution context on which the future is run
    * @return the `Future` holding the result of the computation
    */
    def apply[T](body: =>T)(implicit executor: ExecutionContext): Future[T] =
    ..
    val fut = Future { .. }
    // equivalent to:
    val fut = Future.apply({ .. })

    View full-size slide

  76. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Execution Contexts
    22
    /**
    * An `ExecutionContext` can execute program logic asynchronously,
    * typically but not necessarily on a thread pool.
    *
    * ..
    */
    @implicitNotFound("""Cannot find an implicit ExecutionContext. You might pass
    an (implicit ec: ExecutionContext) parameter to your method
    or import scala.concurrent.ExecutionContext.Implicits.global.""")
    !
    trait ExecutionContext {
    !
    def execute(runnable: Runnable): Unit
    !
    ..
    }

    View full-size slide

  77. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Execution Contexts
    22
    /**
    * An `ExecutionContext` can execute program logic asynchronously,
    * typically but not necessarily on a thread pool.
    *
    * ..
    */
    @implicitNotFound("""Cannot find an implicit ExecutionContext. You might pass
    an (implicit ec: ExecutionContext) parameter to your method
    or import scala.concurrent.ExecutionContext.Implicits.global.""")
    !
    trait ExecutionContext {
    !
    def execute(runnable: Runnable): Unit
    !
    ..
    }

    View full-size slide

  78. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Execution Contexts
    22
    /**
    * An `ExecutionContext` can execute program logic asynchronously,
    * typically but not necessarily on a thread pool.
    *
    * ..
    */
    @implicitNotFound("""Cannot find an implicit ExecutionContext. You might pass
    an (implicit ec: ExecutionContext) parameter to your method
    or import scala.concurrent.ExecutionContext.Implicits.global.""")
    !
    trait ExecutionContext {
    !
    def execute(runnable: Runnable): Unit
    !
    ..
    }
    With suitable mark-
    up, tools could extract quick
    fixes automatically!

    View full-size slide

  79. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Going Further: A Proposal
    23

    View full-size slide

  80. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Going Further: A Proposal
    • Library “explains” control flow in form
    understandable by tools
    23

    View full-size slide

  81. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Going Further: A Proposal
    • Library “explains” control flow in form
    understandable by tools
    • Library implementers add annotations for:
    23

    View full-size slide

  82. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Going Further: A Proposal
    • Library “explains” control flow in form
    understandable by tools
    • Library implementers add annotations for:
    • Saving context information
    23

    View full-size slide

  83. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Going Further: A Proposal
    • Library “explains” control flow in form
    understandable by tools
    • Library implementers add annotations for:
    • Saving context information
    • Indicating which object to attach context
    information with
    23

    View full-size slide

  84. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Going Further: A Proposal
    • Library “explains” control flow in form
    understandable by tools
    • Library implementers add annotations for:
    • Saving context information
    • Indicating which object to attach context
    information with
    • Async tools extract annotations and enable library-
    specific control-flow tracing
    23

    View full-size slide

  85. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Example 1
    24

    View full-size slide

  86. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Example 1
    24
    object Future {
    !
    /** Starts an asynchronous computation and returns a `Future` object..
    *
    */
    @asyncSaveContext
    def apply[T](body: =>T)(implicit executor: ExecutionContext): Future[T] =
    ..

    View full-size slide

  87. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Example 1
    24
    object Future {
    !
    /** Starts an asynchronous computation and returns a `Future` object..
    *
    */
    @asyncSaveContext
    def apply[T](body: =>T)(implicit executor: ExecutionContext): Future[T] =
    ..
    • Save context at invocation site of
    this method

    • Attach context information with
    object returned by this method

    View full-size slide

  88. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Example 2
    25

    View full-size slide

  89. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Example 2
    25
    abstract class ActorRef extends java.lang.Comparable[ActorRef] with
    Serializable {
    ..
    !
    /**
    * Sends the specified message to this ActorRef, i.e. fire-­‐and-­‐forget
    * semantics, including the sender reference if possible.
    *
    * Pass [[akka.actor.ActorRef]] `noSender` or `null` as sender if there is
    * nobody to reply to
    */
    @asyncSaveContext(msg)
    final def tell(msg: Any, sender: ActorRef): Unit = this.!(msg)(sender)
    !
    ..

    View full-size slide

  90. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Example 2
    25
    abstract class ActorRef extends java.lang.Comparable[ActorRef] with
    Serializable {
    ..
    !
    /**
    * Sends the specified message to this ActorRef, i.e. fire-­‐and-­‐forget
    * semantics, including the sender reference if possible.
    *
    * Pass [[akka.actor.ActorRef]] `noSender` or `null` as sender if there is
    * nobody to reply to
    */
    @asyncSaveContext(msg)
    final def tell(msg: Any, sender: ActorRef): Unit = this.!(msg)(sender)
    !
    ..
    Akka actor
    framework

    View full-size slide

  91. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Example 2
    25
    abstract class ActorRef extends java.lang.Comparable[ActorRef] with
    Serializable {
    ..
    !
    /**
    * Sends the specified message to this ActorRef, i.e. fire-­‐and-­‐forget
    * semantics, including the sender reference if possible.
    *
    * Pass [[akka.actor.ActorRef]] `noSender` or `null` as sender if there is
    * nobody to reply to
    */
    @asyncSaveContext(msg)
    final def tell(msg: Any, sender: ActorRef): Unit = this.!(msg)(sender)
    !
    ..
    • Save context at invocation site of
    this method

    • Attach context information with
    argument `msg`
    Akka actor
    framework

    View full-size slide

  92. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Summary
    • Low implementation effort!
    • Leverages knowledge of library designers!
    • High payoff!
    • Still limited
    26

    View full-size slide

  93. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    More Challenges
    27

    View full-size slide

  94. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    More Challenges
    • “Step over”, “step into”, etc.
    27

    View full-size slide

  95. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    More Challenges
    • “Step over”, “step into”, etc.
    • Lost meaning when “steps” cross thread
    boundaries
    27

    View full-size slide

  96. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    More Challenges
    • “Step over”, “step into”, etc.
    • Lost meaning when “steps” cross thread
    boundaries
    • What’s the most useful interpretations of “step
    over/into/return” for a given library?
    27

    View full-size slide

  97. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    More Challenges
    • “Step over”, “step into”, etc.
    • Lost meaning when “steps” cross thread
    boundaries
    • What’s the most useful interpretations of “step
    over/into/return” for a given library?
    • Atomicity of library abstractions
    27

    View full-size slide

  98. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    More Challenges
    • “Step over”, “step into”, etc.
    • Lost meaning when “steps” cross thread
    boundaries
    • What’s the most useful interpretations of “step
    over/into/return” for a given library?
    • Atomicity of library abstractions
    • Atomic methods OK: can step over. Otherwise?
    27

    View full-size slide

  99. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    More Challenges
    • “Step over”, “step into”, etc.
    • Lost meaning when “steps” cross thread
    boundaries
    • What’s the most useful interpretations of “step
    over/into/return” for a given library?
    • Atomicity of library abstractions
    • Atomic methods OK: can step over. Otherwise?
    • Combining concurrency abstractions
    27

    View full-size slide

  100. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Combining Libraries
    • Integration of multiple concurrency libraries natural
    (to some extent)!
    • Developers will do it anyway (see ECOOP ’13)!
    • Have to play nicely together!
    • We discovered many challenges!
    • Most of them have implications for tools
    28

    View full-size slide

  101. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Example: Actors/Futures
    29
    class ActorWithWorkers(workers: ...) extends Actor {
    ...
    !
    def receive = {
    case Do(tasks) =>
    val requests = (tasks zip workers).map {
    case (task, worker) => worker ? task
    }
    val allDone = Future.sequence(requests)
    allDone andThen { seq =>
    sender ! seq.mkString(",")
    }
    }
    }

    View full-size slide

  102. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Example: Actors/Futures
    29
    class ActorWithWorkers(workers: ...) extends Actor {
    ...
    !
    def receive = {
    case Do(tasks) =>
    val requests = (tasks zip workers).map {
    case (task, worker) => worker ? task
    }
    val allDone = Future.sequence(requests)
    allDone andThen { seq =>
    sender ! seq.mkString(",")
    }
    }
    }

    View full-size slide

  103. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Fixed Version
    30
    class ActorWithWorkers(workers: ...) extends Actor {
    ...
    !
    def receive = {
    case Do(tasks) =>
    val from = sender
    !
    val requests = (tasks zip workers).map {
    case (task, worker) => worker ? task
    }
    val allDone = Future.sequence(requests)
    allDone andThen { seq =>
    from ! seq.mkString(",")
    }
    }
    }

    View full-size slide

  104. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Fixed Version
    30
    class ActorWithWorkers(workers: ...) extends Actor {
    ...
    !
    def receive = {
    case Do(tasks) =>
    val from = sender
    !
    val requests = (tasks zip workers).map {
    case (task, worker) => worker ? task
    }
    val allDone = Future.sequence(requests)
    allDone andThen { seq =>
    from ! seq.mkString(",")
    }
    }
    }
    Tool support?

    View full-size slide

  105. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Spores
    • Refinement of closures that demands an explicit
    environment!
    • Supports type-based constraints on captured
    variables
    31

    View full-size slide

  106. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Spores
    • Refinement of closures that demands an explicit
    environment!
    • Supports type-based constraints on captured
    variables
    31
    case Do(tasks) =>
    ..
    !
    val allDone = Future.sequence(requests)
    allDone andThen spore {
    val from = sender
    seq =>
    from ! seq.mkString(",")
    }
    Miller et al. Spores: A Type-Based Foundation for Closures in
    the Age of Concurrency and Distribution. ECOOP ‘14

    View full-size slide

  107. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Spores
    • Refinement of closures that demands an explicit
    environment!
    • Supports type-based constraints on captured
    variables
    31
    case Do(tasks) =>
    ..
    !
    val allDone = Future.sequence(requests)
    allDone andThen spore {
    val from = sender
    seq =>
    from ! seq.mkString(",")
    }
    Miller et al. Spores: A Type-Based Foundation for Closures in
    the Age of Concurrency and Distribution. ECOOP ‘14
    Using spores
    instead of closures
    disallows erroneous
    version!

    View full-size slide

  108. Haller

    High-Level Concurrency Libraries: Challenges for Tools
    Conclusion
    • Concurrency libraries present numerous challenges
    for development tools!
    • Both low-hanging fruit and major challenges!
    • Can we improve the interface between library and
    tool designers?
    32

    View full-size slide