Thread and Queue

前端 未结 6 1476
情深已故
情深已故 2020-12-24 12:28

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 t

6条回答
  •  鱼传尺愫
    2020-12-24 12:58

    I use a gem called work_queue. Its really practic.

    Example:

    require 'work_queue'
    wq = WorkQueue.new 4, 10
    (1..10).each do |number|
        wq.enqueue_b("Thread#{number}") do |thread_name|  
            puts "Hello from the #{thread_name}"
        end
    end
    wq.join
    

提交回复
热议问题