为什么 Ruby 没有内置 ThreadPool? [英] Why doesn't Ruby have a ThreadPool built-in?

查看:38
本文介绍了为什么 Ruby 没有内置 ThreadPool?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,一次创建 10000 个线程,同时运行 8 个.

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

但是 ruby​​ 没有像 Java 那样内置 ThreadPool.有什么好的理由吗?

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

推荐答案

最可能的原因是因为 ruby​​ 没有真正的"线程.它有所谓的绿线.ruby 解释器负责调度执行线程,而不使用任何底层操作系统线程.这有效地使 Ruby 成为单线程.

Most likely the reason is because ruby doesn't have "real" threads. It has what are called Green threads. The ruby interpreter takes care of scheduling execution threads without using any underlying OS threads. This effectively makes Ruby single threaded.

这篇关于为什么 Ruby 没有内置 ThreadPool?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆