Why doesn't Ruby have a ThreadPool built-in?

前端 未结 3 755
隐瞒了意图╮
隐瞒了意图╮ 2021-02-03 13:38

I have a program that creates 10000 threads at once, and runs 8 at the same time.

But ruby doesn\'t have a ThreadPool built-in as Java. Is there a good reason?

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-03 14:06

    probably because it's easy to roll your own using the standard library "Queue" class.

    q = Queue.new
    3.times { Thread.new {  while something = q.pop(true) rescue nil; ... }
    

    It's a good question though--I might suggest bringing it up with Ruby Core.

提交回复
热议问题