Thread and Queue
I am interested in knowing what would be the best way to implement a thread based queue. For example: I have 10 actions which I want to execute with only 4 threads. I would like to create a queue with all the 10 actions placed linearly and start the first 4 action with 4 threads, once one of the thread is done executing, the next one will start etc - So at a time, the number of thread is either 4 or less than 4. Theo There is a Queue class in thread in the standard library. Using that you can do something like this: require 'thread' queue = Queue.new threads = [] # add work to the queue queue