我知道红宝石的“合作”线程使用绿色线程。如何在我的应用程序中创建真正的“操作系统级”线程,以便使用多个cpu内核进行处理?
当前回答
因为不能编辑那个答案,所以在这里添加一个新的回答。
更新(2017-05-08)
这篇文章很旧了,信息也跟不上时代 (2017)胎面,以下是一些补充:
Opal is a Ruby to JavaScript source-to-source compiler. It also has an implementation of the Ruby corelib, It current very active develompent, and exist a great deal of (frontend) framework worked on it. and production ready. Because base on javascript, it not support parallel threads. truffleruby is a high performance implementation of the Ruby programming language. Built on the GraalVM by Oracle Labs,TruffleRuby is a fork of JRuby, combining it with code from the Rubinius project, and also containing code from the standard implementation of Ruby, MRI, still live development, not production ready. This version ruby seem like born for performance, I don't know if support parallel threads, but I think it should.
其他回答
使用drb怎么样?它不是真正的多线程,而是几个进程之间的通信,但你现在可以在1.8中使用它,而且它的阻力相当低。
如果您确实需要Ruby在产品级系统中的并行性(您不能使用beta),那么进程可能是更好的选择。 但是,首先在JRuby下尝试线程绝对是值得的。
另外,如果您对Ruby下线程的未来感兴趣,您可能会发现本文很有用。
Ruby 1.8只有绿色线程,没有办法创建一个真正的“操作系统级”线程。但是,ruby 1.9将有一个叫做光纤的新特性,它将允许您创建实际的操作系统级线程。不幸的是,Ruby 1.9仍处于测试阶段,预计几个月后就会稳定下来。
另一种选择是使用JRuby。JRuby将线程实现为操作系统级别的头,其中没有“绿色线程”。JRuby的最新版本是1.1.4,相当于Ruby 1.8
因为不能编辑那个答案,所以在这里添加一个新的回答。
更新(2017-05-08)
这篇文章很旧了,信息也跟不上时代 (2017)胎面,以下是一些补充:
Opal is a Ruby to JavaScript source-to-source compiler. It also has an implementation of the Ruby corelib, It current very active develompent, and exist a great deal of (frontend) framework worked on it. and production ready. Because base on javascript, it not support parallel threads. truffleruby is a high performance implementation of the Ruby programming language. Built on the GraalVM by Oracle Labs,TruffleRuby is a fork of JRuby, combining it with code from the Rubinius project, and also containing code from the standard implementation of Ruby, MRI, still live development, not production ready. This version ruby seem like born for performance, I don't know if support parallel threads, but I think it should.
如果您正在使用MRI,那么您可以用C编写线程代码作为扩展或使用ruby-inline gem。
推荐文章
- 是否可以在MiniTest中运行单个测试?
- 如何在Ruby中生成a和b之间的随机数?
- 自动化invokerrequired代码模式
- 无法安装gem -未能建立gem本地扩展-无法加载这样的文件——mkmf (LoadError)
- c#线程安全快速(est)计数器
- 如何将此foreach代码转换为Parallel.ForEach?
- 如何在Ruby中创建文件
- 什么是Ruby文件。开放模式和选项?
- Ruby数组到字符串的转换
- 如何分割(块)一个Ruby数组成X元素的部分?
- Ruby中“or”和||的区别?
- 如何测试参数是否存在在轨道
- 并发HashSet<T>在。net框架?
- 在Ruby中不创建新字符串而修饰字符串的规范方法是什么?
- RVM不是一个函数,用' RVM use…’不会起作用