Skip to content

Instantly share code, notes, and snippets.

@samg
Created October 23, 2013 16:33
Show Gist options
  • Save samg/7121980 to your computer and use it in GitHub Desktop.
Save samg/7121980 to your computer and use it in GitHub Desktop.
Advanced Multithreading talk at Cascadia Ruby
Jerry D'Antonio
github.com/jdantonio (all code, slides, and notes in a repo on github)
@jerrydantonio
From Ohio
Works at a Ruby and Erlang shop.
Asynchronous
The old way is to use locks around resources.
Better paradigm is to use asynchronous concurrency.
This paradigm is being built into most languages but not Ruby.
Shared mutable state is really bad.
FUTURE
One good concurrency concept is a "Future" from clojure
There is a "concurrent" gem that implements this pattern in Ruby.
Ruby's observable library is useful here.
AGENT
Agent is another core concept from clojure
You get the current value from the agent, manipulate it and pass a new value
back. That becomes the new value of the agent.
Also support the Observable pattern.
There are no immutable variables in Ruby which means you have to be careful
not to mutate the internal state of the Agent.
Ideal hash tree - immutable threadsafe data structure.
The hamster gem implements this.
There's also a "thread_safe" library that's written by a jruby core member.
PROMISE
Like a future but it's chainable. Popular in JS.
ACTOR
Used in scala. Concurrent library implements actors.
Supervisor manages actor, which makes erlang very fault tolerant.
"Let it fail"
Pattern first proposed at MIT in 1973
Celluloid is another ruby library that implements the actor pattern in Ruby
REACTOR PATTERN
event loop runs forever
demultiplexers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment