$30 off During Our Annual Pro Sale. View Details »

Threads Aren't Evil

Threads Aren't Evil

To skip to actual technical content go to slide 71 https://speakerdeck.com/schneems/threads-arent-evil?slide=71 the first slides make no sense without narration.

Okay, so threads are pretty evil.

But they are also useful, and given the right development patterns: not impossible to work with.

In this talk you'll look at some real Ruby libraries where threads were applied to accomplish otherwise impossible tasks. We'll look at re-writing a synchronous library to support parallel execution for performance gains. We'll also talk about the operating system internals of exactly what makes a thread a thread.

If you're not comfortable with the "T" word (threads), this talk is the perfect introduction to practical concurrent programming in Ruby.

Richard Schneeman

September 26, 2017
Tweet

More Decks by Richard Schneeman

Other Decks in Technology

Transcript

  1. Threads
    Aren’t
    Evil
    @schneems

    View Slide

  2. Threads

    View Slide

  3. Are

    View Slide

  4. Not

    View Slide

  5. Evil

    View Slide

  6. View Slide

  7. View Slide

  8. “Ruby doesn’t
    have real threads”

    View Slide

  9. “Ruby doesn’t
    have real threads”

    View Slide

  10. “Ruby doesn’t
    have real threads”

    View Slide

  11. “Ruby is
    incapable of using
    threads because of
    the GIL

    View Slide

  12. “Ruby is
    incapable of using
    threads because of
    the GIL

    View Slide

  13. “Ruby is
    incapable of using
    threads because of
    the GIL

    View Slide

  14. "Rails is not able
    to run on threads
    so we can't use
    them in Ruby"

    View Slide

  15. "Rails is not able
    to run on threads
    so we can't use
    them in Ruby"

    View Slide

  16. "My ruby code is
    not thread safe
    and will not run in
    threads"

    View Slide

  17. What do you hear?

    View Slide

  18. “doesn’t”

    View Slide

  19. “incapable”

    View Slide

  20. “not able”

    View Slide

  21. “will not”

    View Slide

  22. 2012

    View Slide

  23. 2013

    View Slide

  24. 2013

    View Slide

  25. 2013

    View Slide

  26. 2013

    View Slide

  27. “doesn’t”

    View Slide

  28. “incapable”

    View Slide

  29. “not able”

    View Slide

  30. “will not”

    View Slide

  31. View Slide

  32. 1490

    View Slide

  33. View Slide

  34. View Slide

  35. View Slide

  36. 1490

    View Slide

  37. 1490

    View Slide

  38. 1490

    View Slide

  39. 1490

    View Slide

  40. 1490

    View Slide

  41. 1490

    View Slide

  42. 1490

    View Slide

  43. View Slide

  44. цинга

    View Slide

  45. цинга

    View Slide

  46. цинга

    View Slide

  47. цинга

    View Slide

  48. View Slide

  49. View Slide

  50. View Slide

  51. View Slide

  52. View Slide

  53. View Slide

  54. View Slide

  55. View Slide

  56. Problem Solved?

    View Slide

  57. View Slide

  58. View Slide

  59. View Slide

  60. View Slide

  61. View Slide

  62. View Slide

  63. View Slide

  64. View Slide

  65. The Future

    View Slide

  66. BTW

    View Slide

  67. Find me
    @schneems

    View Slide

  68. https://
    www.
    schneems
    .com

    View Slide

  69. View Slide

  70. View Slide

  71. Who here knows
    what a thread is?

    View Slide

  72. Process
    Address Space

    View Slide

  73. Process
    Address Space
    - code

    View Slide

  74. Process
    Address Space
    - code
    - data

    View Slide

  75. Process
    Address Space
    - code
    - data
    - register

    View Slide

  76. Process
    Address Space
    - code
    - data
    - register
    - stack

    View Slide

  77. Process
    Address Space
    - code
    - data
    - register
    - stack

    View Slide

  78. #include
    int increment(int x) {
    return x + 1;
    }
    int main() {
    int i = 0;
    printf("Incremented to: %i\n", increment(i))
    }

    View Slide

  79. _main:
    100000f40: 55 pushq %rbp
    100000f41: 48 89 e5 movq %rsp, %rbp
    100000f44: 48 83 ec 10 subq $16, %rsp
    100000f48: c7 45 fc 00 00 00 00 movl $0, -4(%rbp)
    100000f4f: c7 45 f8 00 00 00 00 movl $0, -8(%rbp)
    100000f56: 83 7d f8 0a cmpl $10, -8(%rbp)
    100000f5a: 0f 8d 1f 00 00 00 jge 31 <_main+3F>
    100000f60: 48 8d 3d 43 00 00 00 leaq 67(%rip), %rdi
    100000f67: b0 00 movb $0, %al
    100000f69: e8 1a 00 00 00 callq 26
    100000f6e: 89 45 f4 movl %eax, -12(%rbp)
    100000f71: 8b 45 f8 movl -8(%rbp), %eax
    100000f74: 83 c0 01 addl $1, %eax
    100000f77: 89 45 f8 movl %eax, -8(%rbp)
    100000f7a: e9 d7 ff ff ff jmp -41 <_main+16>
    100000f7f: 8b 45 fc movl -4(%rbp), %eax
    100000f82: 48 83 c4 10 addq $16, %rsp
    100000f86: 5d popq %rbp
    100000f87: c3 retq

    View Slide

  80. _main:
    100000f40: 55 pushq %rbp
    100000f41: 48 89 e5 movq %rsp, %rbp
    100000f44: 48 83 ec 10 subq $16, %rsp
    100000f48: c7 45 fc 00 00 00 00 movl $0, -4(%rbp)
    100000f4f: c7 45 f8 00 00 00 00 movl $0, -8(%rbp)
    100000f56: 83 7d f8 0a cmpl $10, -8(%rbp)
    100000f5a: 0f 8d 1f 00 00 00 jge 31 <_main+3F>
    100000f60: 48 8d 3d 43 00 00 00 leaq 67(%rip), %rdi
    100000f67: b0 00 movb $0, %al
    100000f69: e8 1a 00 00 00 callq 26
    100000f6e: 89 45 f4 movl %eax, -12(%rbp)
    100000f71: 8b 45 f8 movl -8(%rbp), %eax
    100000f74: 83 c0 01 addl $1, %eax
    100000f77: 89 45 f8 movl %eax, -8(%rbp)
    100000f7a: e9 d7 ff ff ff jmp -41 <_main+16>
    100000f7f: 8b 45 fc movl -4(%rbp), %eax
    100000f82: 48 83 c4 10 addq $16, %rsp
    100000f86: 5d popq %rbp
    100000f87: c3 retq

    View Slide

  81. _main:
    100000f40: 55 pushq %rbp
    100000f41: 48 89 e5 movq %rsp, %rbp
    100000f44: 48 83 ec 10 subq $16, %rsp
    100000f48: c7 45 fc 00 00 00 00 movl $0, -4(%rbp)
    100000f4f: c7 45 f8 00 00 00 00 movl $0, -8(%rbp)
    100000f56: 83 7d f8 0a cmpl $10, -8(%rbp)
    100000f5a: 0f 8d 1f 00 00 00 jge 31 <_main+3F>
    100000f60: 48 8d 3d 43 00 00 00 leaq 67(%rip), %rdi
    100000f67: b0 00 movb $0, %al
    100000f69: e8 1a 00 00 00 callq 26
    100000f6e: 89 45 f4 movl %eax, -12(%rbp)
    100000f71: 8b 45 f8 movl -8(%rbp), %eax
    100000f74: 83 c0 01 addl $1, %eax
    100000f77: 89 45 f8 movl %eax, -8(%rbp)
    100000f7a: e9 d7 ff ff ff jmp -41 <_main+16>
    100000f7f: 8b 45 fc movl -4(%rbp), %eax
    100000f82: 48 83 c4 10 addq $16, %rsp
    100000f86: 5d popq %rbp
    100000f87: c3 retq

    View Slide

  82. _main:
    100000f40: 55 pushq %rbp
    100000f41: 48 89 e5 movq %rsp, %rbp
    100000f44: 48 83 ec 10 subq $16, %rsp
    100000f48: c7 45 fc 00 00 00 00 movl $0, -4(%rbp)
    100000f4f: c7 45 f8 00 00 00 00 movl $0, -8(%rbp)
    100000f56: 83 7d f8 0a cmpl $10, -8(%rbp)
    100000f5a: 0f 8d 1f 00 00 00 jge 31 <_main+3F>
    100000f60: 48 8d 3d 43 00 00 00 leaq 67(%rip), %rdi
    100000f67: b0 00 movb $0, %al
    100000f69: e8 1a 00 00 00 callq 26
    100000f6e: 89 45 f4 movl %eax, -12(%rbp)
    100000f71: 8b 45 f8 movl -8(%rbp), %eax
    100000f74: 83 c0 01 addl $1, %eax
    100000f77: 89 45 f8 movl %eax, -8(%rbp)
    100000f7a: e9 d7 ff ff ff jmp -41 <_main+16>
    100000f7f: 8b 45 fc movl -4(%rbp), %eax
    100000f82: 48 83 c4 10 addq $16, %rsp
    100000f86: 5d popq %rbp
    100000f87: c3 retq

    View Slide

  83. #include
    int increment(int x) {
    return x + 1;
    }
    int main() {
    int i = 0;
    printf("Incremented to: %i\n", increment(i))
    }

    View Slide

  84. #include
    int increment(int x) {
    return x + 1;
    }
    int main() {
    int i = 0;
    printf("Incremented to: %i\n", increment(i))
    }

    View Slide

  85. #include
    int increment(int x) {
    return x + 1;
    }
    int main() {
    int i = 0;
    printf("Incremented to: %i\n", increment(i))
    }

    View Slide

  86. #include
    int increment(int x) {
    return x + 1;
    }
    int main() {
    int i = 0;
    printf("Incremented to: %i\n", increment(i))
    }

    View Slide

  87. #include
    int increment(int x) {
    return x + 1;
    }
    int main() {
    int i = 0;
    printf("Incremented to: %i\n", increment(i))
    }

    View Slide

  88. Thanks to
    Julia Evans
    For the example code
    https://jvns.ca

    View Slide

  89. Process
    Address Space
    - code
    - data
    - register
    - stack

    View Slide

  90. Process
    Address Space
    - code
    - data
    - register
    - stack

    View Slide

  91. Process Control Block
    Process State
    Process Number
    Program Counter
    Registers
    Memory Limits
    List of open Files
    Signal Mask
    CPU Scheduling info
    (PCB)

    View Slide

  92. View Slide

  93. Process
    - code
    - data
    - register
    - stack

    View Slide

  94. Process
    - code
    - data
    - register
    - stack
    CPU

    View Slide

  95. Process
    - code
    - data
    - register
    - stack




    Input
    Output
    (IO)

    View Slide

  96. Process
    - code
    - data
    - register
    - stack




    Input
    Output
    (IO)

    View Slide

  97. Process
    - code
    - data
    - register
    - stack




    Input
    Output
    (IO)

    View Slide

  98. View Slide

  99. View Slide

  100. View Slide

  101. Pros?

    View Slide

  102. Better CPU
    utilization

    View Slide

  103. Cons?

    View Slide

  104. Need lots of
    processes

    View Slide

  105. Processes take
    up memory
    which is a finite
    resource

    View Slide

  106. Loading and
    unloading a PCB
    is expensive

    View Slide

  107. Sharing data
    between
    processes is
    HARD

    View Slide

  108. View Slide

  109. View Slide

  110. View Slide

  111. Introducing

    View Slide

  112. Threads

    View Slide

  113. Process
    - code
    - data
    - register
    - stack

    View Slide

  114. Process
    - code
    - data
    - register
    - stack

    View Slide

  115. Process
    - code
    - data
    - register
    - stack

    View Slide

  116. Process
    register
    stack

    View Slide

  117. Process
    register
    stack
    ⚡ ⚡ ⚡
    register
    stack
    register
    stack

    View Slide

  118. Pros?

    View Slide

  119. Better CPU
    utilization

    View Slide

  120. Reuse existing
    process memory
    (code and data)

    View Slide

  121. Smaller Context
    Switch Time

    View Slide

  122. Cons?

    View Slide

  123. Shared code +
    shared data =

    View Slide

  124. Shared code +
    shared data =

    View Slide

  125. Threads are
    simple

    View Slide

  126. Threads are hard

    View Slide

  127. In every language
    *

    View Slide

  128. It’s possible to
    avoid threads

    View Slide

  129. Javascript
    is single threaded

    View Slide

  130. Threading is
    easier in some
    languages

    View Slide

  131. Functional
    languages (can)
    make threading
    easy

    View Slide

  132. Functional
    languages make
    side effects
    impossible

    View Slide

  133. Which makes
    coding harder
    (IMHO)

    View Slide

  134. OMSCS

    View Slide

  135. Threading sucks
    (less) in Ruby

    View Slide

  136. Are threads just
    for performance?

    View Slide

  137. Nope

    View Slide

  138. Thread.new do
    while @running
    sleep @timeout
    @reaper.reap
    end
    end

    View Slide

  139. Thread.new do
    while @running
    sleep @timeout
    @reaper.reap
    end
    end

    View Slide

  140. Was that scary?

    View Slide

  141. Are threads scary?

    View Slide

  142. (hint: no)

    View Slide

  143. Any other
    examples?

    View Slide

  144. @background_worker_thread = Thread.new do
    @background_worker.start {
    ScoutApm::Debug.instance.call_periodic_hooks
    ScoutApm::Agent.instance.process_metrics
    clean_old_percentiles
    }
    end

    View Slide

  145. What about the
    GVL?

    View Slide

  146. array = Array.new(100) { String.new }
    t1 = Thread.new do
    array.each {|x| x.prepend("hello") }
    end
    t2 = Thread.new do
    array.each {|x| x << " world" }
    end
    t1.join; t2.join
    puts array

    View Slide

  147. hello world
    hello world
    hello world
    hello world
    hello world
    hello world
    hello world
    hello world

    View Slide

  148. hello world
    hello world
    hello world
    hello world
    hello world
    hello world
    hello world
    hello world

    View Slide

  149. What did the GVL
    do?

    View Slide

  150. array = Array.new(100) { String.new }
    t1 = Thread.new do
    array.each {|x| x.prepend("hello") }
    end
    t2 = Thread.new do
    array.each {|x| x << " world" }
    end
    t1.join; t2.join
    puts array

    View Slide

  151. array = Array.new(100) { String.new }
    t1 = Thread.new do
    array.each {|x| x.prepend("hello") }
    end
    t2 = Thread.new do
    array.each {|x| x << " world" }
    end
    t1.join; t2.join
    puts array

    View Slide

  152. GVL means we
    cannot see speed
    increase just by
    using threads

    View Slide

  153. View Slide

  154. GVL is released
    when we do IO!

    View Slide

  155. array = Array.new(100) { String.new }
    t1 = Thread.new do
    uri = URI.parse(“http://example.com/hello")
    hi = Net::Http.get(uri)
    array.each {|x| x.prepend(hi) }
    end
    t2 = Thread.new do
    uri = URI.parse(“http://example.com/hello")
    world = Net::Http.get(uri)
    array.each {|x| x << world }
    end
    t1.join; t2.join
    puts array

    View Slide

  156. When is the GVL
    released exactly?

    View Slide

  157. void *
    rb_thread_call_without_gvl2(void *(*func)(void *),
    void *data1, rb_unblock_function_t *ubf, void *data2)
    {
    return call_without_gvl(func, data1, ubf, data2,
    TRUE);
    }
    void *
    rb_thread_call_without_gvl(void *(*func)(void *data),
    void *data1, rb_unblock_function_t *ubf, void *data2)
    {
    return call_without_gvl(func, data1, ubf, data2,
    FALSE);
    }

    View Slide

  158. void *
    rb_thread_call_without_gvl2(void *(*func)(void *),
    void *data1, rb_unblock_function_t *ubf, void *data2)
    {
    return call_without_gvl(func, data1, ubf, data2,
    TRUE);
    }
    void *
    rb_thread_call_without_gvl(void *(*func)(void *data),
    void *data1, rb_unblock_function_t *ubf, void *data2)
    {
    return call_without_gvl(func, data1, ubf, data2,
    FALSE);
    }

    View Slide

  159. Use a debugger to
    see GVL get
    released!

    View Slide

  160. $ lldb ruby scratch.rb
    breakpoint set --name
    rb_thread_call_without_gvl
    breakpoint set --name
    rb_thread_call_without_gv2

    View Slide

  161. $ lldb ruby scratch.rb
    breakpoint set --name
    rb_thread_call_without_gvl
    breakpoint set --name
    rb_thread_call_without_gv2

    View Slide

  162. $ lldb ruby scratch.rb
    breakpoint set --name
    rb_thread_call_without_gvl
    breakpoint set --name
    rb_thread_call_without_gv2

    View Slide

  163. Now run

    View Slide

  164. $ lldb ruby scratch.rb
    breakpoint set --name
    rb_thread_call_without_gvl
    breakpoint set --name
    rb_thread_call_without_gv2
    run

    View Slide

  165. When we hit a
    pause, find the
    backtrace with

    View Slide

  166. call rb_backtrace()

    View Slide

  167. require ‘net/http'
    url = “https://www.schneems.com"
    uri = URI.parse(url)
    response = Net::HTTP.get(uri)
    puts response

    View Slide

  168. require ‘net/http'
    url = “https://www.schneems.com"
    uri = URI.parse(url)
    response = Net::HTTP.get(uri)
    puts response

    View Slide

  169. require ‘net/http'
    url = “https://www.schneems.com"
    uri = URI.parse(url)
    response = Net::HTTP.get(uri)
    puts response

    View Slide

  170. require ‘net/http'
    url = “https://www.schneems.com"
    uri = URI.parse(url)
    response = Net::HTTP.get(uri)
    puts response

    View Slide

  171. require ‘net/http'
    url = “https://www.schneems.com"
    uri = URI.parse(url)
    response = Net::HTTP.get(uri)
    puts response

    View Slide

  172. require ‘net/http'
    url = “https://www.schneems.com"
    uri = URI.parse(url)
    response = Net::HTTP.get(uri)
    puts response

    View Slide

  173. None of the
    above?

    View Slide

  174. Use the debugger!

    View Slide

  175. 1309 {
    1310 void *val = 0;
    1311
    -> 1312 rb_thread_t *th = GET_THREAD();
    1313 int saved_errno = 0;
    1314
    1315 if (ubf == RUBY_UBF_IO || ubf == RUBY_UBF_PROCESS) {
    (lldb) call rb_backtrace()
    from :4:in `'
    from :4:in `require'
    from.../rubygems.rb:1363:in `'
    from.../rubygems/specification.rb:873:in `load_defaults'
    from.../rubygems/specification.rb:821:in `each_spec'
    from.../rubygems/specification.rb:743:in `each_gemspec'
    from.../rubygems/specification.rb:743:in `each'
    from.../rubygems/specification.rb:744:in `block in each_gemspec'
    from.../rubygems/specification.rb:744:in `each'
    from.../rubygems/specification.rb:745:in `block (2 levels) in each_gemspec'
    from.../rubygems/specification.rb:822:in `block in each_spec'
    from.../rubygems/specification.rb:1161:in `load'
    from.../rubygems/specification.rb:1161:in `read'
    (lldb)

    View Slide

  176. require ‘net/http'
    url = “https://www.schneems.com"
    uri = URI.parse(url)
    response = Net::HTTP.get(uri)
    puts response

    View Slide

  177. I told a small lie

    View Slide

  178. void *
    rb_thread_call_without_gvl2(void *(*func)(void *),
    void *data1, rb_unblock_function_t *ubf, void *data2)
    {
    return call_without_gvl(func, data1, ubf, data2,
    TRUE);
    }
    void *
    rb_thread_call_without_gvl(void *(*func)(void *data),
    void *data1, rb_unblock_function_t *ubf, void *data2)
    {
    return call_without_gvl(func, data1, ubf, data2,
    FALSE);
    }

    View Slide

  179. #define GVL_UNLOCK_BEGIN() do { \
    rb_thread_t *_th_stored = GET_THREAD(); \
    RB_GC_SAVE_MACHINE_CONTEXT(_th_stored); \
    gvl_release(_th_stored->vm);
    #define GVL_UNLOCK_END() \
    gvl_acquire(_th_stored->vm, _th_stored);
    \
    rb_thread_set_current(_th_stored); \
    } while(0)

    View Slide

  180. BTW, you don’t
    need to know how
    to do this.

    View Slide

  181. I’m just showing
    you it’s not magic

    View Slide

  182. Recap: Threads
    are not…

    View Slide

  183. Recap: Threads
    are not evil

    View Slide

  184. Recap: GVL is not
    magic

    View Slide

  185. How do we start
    using threads?

    View Slide

  186. Make a Toy
    threading library!

    View Slide

  187. It’s fun I promise

    View Slide

  188. Make a worker
    thread

    View Slide

  189. require ‘thread
    my_queue = Queue.new
    my_thread = Thread.new do
    loop do
    job = my_queue.pop
    job.call
    end
    end

    View Slide

  190. require ‘thread
    my_queue = Queue.new
    my_thread = Thread.new do
    loop do
    job = my_queue.pop
    job.call
    end
    end

    View Slide

  191. require ‘thread
    my_queue = Queue.new
    my_thread = Thread.new do
    loop do
    job = my_queue.pop
    job.call
    end
    end

    View Slide

  192. require ‘thread
    my_queue = Queue.new
    my_thread = Thread.new do
    loop do
    job = my_queue.pop
    job.call
    end
    end

    View Slide

  193. Use a worker
    thread via a
    “boss” i.e. main

    View Slide

  194. 10.times {
    job = Proc.new { puts "hello" }
    my_queue.push(job)
    }

    View Slide

  195. It works!

    View Slide

  196. But there are bugs

    View Slide

  197. How can we be
    sure that all jobs
    are finished?

    View Slide

  198. Join the thread

    View Slide

  199. require 'thread'
    my_queue = Queue.new
    my_thread = Thread.new do
    loop do
    job = my_queue.pop
    job.call
    end
    end
    10.times {
    job = Proc.new { puts "hello" }
    my_queue.push(job)
    }
    my_thread.join

    View Slide

  200. Infinite loop

    View Slide

  201. Why?

    View Slide

  202. require ‘thread
    my_queue = Queue.new
    my_thread = Thread.new do
    loop do
    job = my_queue.pop
    job.call
    end
    end

    View Slide

  203. Poison our queue

    View Slide

  204. my_queue = Queue.new
    POISON = Object.new
    my_thread = Thread.new do
    loop do
    job = my_queue.pop
    break if job == POISON
    job.call
    end
    end

    View Slide

  205. require 'thread'
    my_queue = Queue.new
    POISON = Object.new
    my_thread = Thread.new do
    loop do
    job = my_queue.pop
    break if job == POISON
    job.call
    end
    end
    10.times {
    job = Proc.new { puts "hello" }
    my_queue.push(job)
    }
    my_queue.push(POISON)
    my_thread.join

    View Slide

  206. Exercise: Build a
    thread pool that
    has multiple
    threads

    View Slide

  207. To poison multiple
    workers, add multiple
    poison objects into
    pool

    View Slide

  208. Threads are not…

    View Slide

  209. Threads are not
    evil

    View Slide

  210. GVL is not magic

    View Slide

  211. There are other
    thread constructs

    View Slide

  212. Mutex

    View Slide

  213. Condition
    Variable

    View Slide

  214. You can ignore most
    of them if you use a
    queue and boss/
    worker pattern.

    View Slide

  215. How do I
    _actually_ use
    threads?

    View Slide

  216. concurrent_ruby

    View Slide

  217. require 'concurrent'
    10.times {
    Concurrent::Promise.execute(
    executor: :fast) do
    puts "hello"
    end
    }

    View Slide

  218. require 'concurrent'
    10.times {
    Concurrent::Promise.execute(
    executor: :fast) do
    puts "hello"
    end
    }

    View Slide

  219. require 'concurrent'
    10.times {
    Concurrent::Promise.execute(
    executor: :fast) do
    puts "hello"
    end
    }

    View Slide

  220. Protip!

    View Slide

  221. Always call wait!

    View Slide

  222. Sprockets
    Example

    View Slide

  223. After we process
    an asset we have
    to write it to disk

    View Slide

  224. We also want a
    gzip file etc.

    View Slide

  225. File writes release
    the GVL

    View Slide

  226. Use Concurrent
    Ruby!

    View Slide

  227. promise = Concurrent::Promise.execute(
    executor: executor) do
    exporter.call
    end
    concurrent_exporters << promise

    View Slide

  228. promise = Concurrent::Promise.execute(
    executor: executor) do
    exporter.call
    end
    concurrent_exporters << promise

    View Slide

  229. concurrent_exporters.each(&:wait!)

    View Slide

  230. Here’s how to use
    threads

    View Slide

  231. Find where the
    GVL is released

    View Slide

  232. GVL is released
    where there is IO

    View Slide

  233. Where there is IO,
    threads are an
    amazing
    performance fit

    View Slide

  234. Create a job

    View Slide

  235. Make sure the job
    finishes

    View Slide

  236. Handle shared
    variable access
    (via atomic
    structures)

    View Slide

  237. Handle shared
    variable access
    (via atomic
    structures)

    View Slide

  238. What about
    guilds?

    View Slide

  239. Guilds aren’t
    released

    View Slide

  240. Can still use
    threads from
    within a guild

    View Slide

  241. Remember our
    explorers

    View Slide

  242. 1875

    View Slide

  243. 1875

    View Slide

  244. 1875

    View Slide

  245. 1875

    View Slide

  246. ☠☠☠

    View Slide

  247. Webrick is slow

    View Slide

  248. Webrick is slow

    View Slide

  249. Talk about what
    you DON’T
    know

    View Slide

  250. Talk about what
    you DON’T
    know

    View Slide

  251. Talk about what
    you DON’T
    know

    View Slide

  252. Share
    assumptions

    View Slide

  253. Share
    assumptions

    View Slide

  254. Threads are a tool

    View Slide

  255. Threads can be
    useful

    View Slide

  256. Threads can be
    fast

    View Slide

  257. View Slide

  258. View Slide

  259. View Slide

  260. View Slide

  261. View Slide

  262. View Slide

  263. Threads

    View Slide

  264. Are

    View Slide

  265. Not

    View Slide

  266. Evil

    View Slide

  267. Any Questions?

    View Slide

  268. View Slide