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

Cond: A Case Study; or Shipping Fn Channels

Cond: A Case Study; or Shipping Fn Channels

A defense against killing sync.Cond, and explaining it so that more people will have it as part of their toolbox! Includes full advertisement!

Reed Allman

April 25, 2018
Tweet

More Decks by Reed Allman

Other Decks in Technology

Transcript

  1. And users don't want to wait 4 years for native

    support for their favorite programming language
  2. First, define the problem: • Parent wait for children to

    finish • Producer/Consumer problem
  3. We need to allocate resources from a host (disk, memory,

    CPU) dynamically per container, and when full, wait for resources to free up. Meanwhile, if any of the existing containers free up, we can use them and abandon attempting to allocate more resources.
  4. This problem is called a covering condition [1] Remzi H.

    Arpaci-Dusseau and Andrea C. Arpaci-Dusseau, Operating Systems: Three Easy Pieces, 30.3, 2015 [2] B.W. Lampson, D.R. Redell, Experience with Processes and Monitors in Mesa, pg. 105, 1980
  5. We need to wake up all threads when a container

    exits, because multiple containers could fill its void and certain containers may not fit at all
  6. While channels can do broadcast, afterwards the channel is closed.

    We really need a channel that remains open but allows broadcasts.
  7. Mostly, it's an issue of complexity. We could implement this

    all with channels, but we'd need a few things: • requests wait over resource allocation channel • a thread (or synchronization) that manages resource allocation channels & their requested sizes (FIFO), and separately receives wake up calls when resources are freed and doles them out (and handles when allocs gave up efficiently) • to figure out whatever the hell data structure ^ is
  8. sync.Cond and channels don't mix out of the box, so

    wouldn't we be better off just doing this all with channels and get this fo free?
  9. What we accomplished: • Now we can wait for resources

    OR a container to free up, OR a request timeout, using a select statement • You were duped into watching an advertisement for the Fn Project under the false pretense that you might learn something from somebody you have never heard of