Skip to content

Instantly share code, notes, and snippets.

View akshayrao14's full-sized avatar
💭
Building TERN

Akshay Rao akshayrao14

💭
Building TERN
  • New Delhi, India
View GitHub Profile
@akshayrao14
akshayrao14 / thread-pool.rb
Last active December 4, 2018 13:56 — forked from rosenfeld/thread-pool.rb
Simple thread pool implementation in Ruby - modified #run to return new thread instead of all running threads
require 'thread' # for Mutex: Ruby doesn't provide out of the box thread-safe arrays
# NOTE: Modifications from original:
# => 1. The instance variable @running_threads has been removed, because
# => the size of this array never decreases.
# => 2. Did not need the #await_completion instance method
# => 3. Added a class method #wait_for_threads that accepts an array of threads
# and joins them
class ThreadPool