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

Project Loom: Fibers and Continuations

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

Project Loom: Fibers and Continuations

Avatar for Daniel Castillo

Daniel Castillo

November 25, 2019
Tweet

More Decks by Daniel Castillo

Other Decks in Programming

Transcript

  1. Agenda • Concepts & Current State • Project Loom •

    Demo • Next steps • Questions 3
  2. Concepts A thread is the smallest sequence of programmed instructions

    that can be managed independently by a scheduler 6
  3. Current State ◦ Threads have a significant footprint ◦ Are

    hard to create, to control and to understand ◦ Have a lot of baggage 7
  4. Current State ◦ Synchronous applications are simpler but less scalable.

    ◦ Asynchronous applications are scalable, complex and really hard to debug and profile. 8
  5. Current State: Monads 9 ◦ An abstract type used to

    represent computations, allows to the user to chain actions like a pipeline. ◦ Basically makes a composition of actions and then ask for the final result.
  6. 10

  7. 12

  8. 13 The main goal is to make it possible to

    write code that is essentially simple, synchronous blocking code that is easy to read, to write, to profile and is scalable
  9. 14 Project Loom ◦ Bringing lightweight concurrency to the JVM

    ◦ Lower footprint, because threads are too damn expensive! ◦ Make concurrency simple again!
  10. 16 Continuations A Continuation is a program object representing a

    computation that might be suspended and resume
  11. 17

  12. 18

  13. 19 Fibers ◦ Fibers are lightweight or user-mode threads scheduled

    by the JVM not by the OS ◦ Very low memory footprint (If is it done right you can allocate millions)
  14. 20 Fibers ◦ Basically a fiber wraps a task into

    a continuation and schedules it into a carrier thread • The continuation yields when the task needs to block • The continuation is continued when the task is ready to continue ◦ Default scheduler is a ForkJoinPool
  15. 22

  16. 23 Cancellations ◦ Each fiber has a cancellation status and

    can’t be reset ◦ Fiber::cancel • Sets the cancel status • Unparks the fiber ◦ The cancellation is cooperative and can be grabbed by the task
  17. 28 Resources ◦ https://openjdk.java.net/projects/loom/ ◦ https://wiki.openjdk.java.net/display/loom/Main ◦ Project Loom Update

    with Alan Bateman and Rickard Bäckman ◦ Ron Pressler - Loom: Bringing Lightweight Threads and Delimited Continuations to the JVM ◦ https://vorpus.org/blog/notes-on-structured-concurrency-or-go-state ment-considered-harmful/ ◦ https://vorpus.org/blog/timeouts-and-cancellation-for-humans/ ◦ http://250bpm.com/blog:71