Feature #14792

Multiple RubyVM in one process to make real multi-threading.

Added by HfCloud (Xiangyu Shi) over 2 years ago. Updated over 2 years ago.

Target version:


This is an old problem, maybe running multiple RubyVM is a good way, which can really run ruby code in parallel in one process (Each thread runs a RubyVM)and be compatible with old codes(If some codes depend on the GIL, they can still work properly). Some other programming languages have successfully realize it(It is said that lua uses this method, and my friend has make real multi-threading javascript by running multiple ES VM, threads can share data by passing pointers(safe problem is guaranteed by the programmer)).

Why do I have this requirement :
Really parallel threads needed, I choose ruby as the script language in my game engine( And in some situations, I don't need to do too much computation, but I hope they are really running in parallel. (for example,I divide rendering and logic into 2 parts and dispatch them onto two different threads, (putting rendering and logic in one thread is really not a good design)). The logic threads(logic threads are called 'producer', there can be many logic threads) will submit rendering commands list to the rendering thread('consumer'). This process requires to be highly real-time(maybe 3000 times per second), and multi-process will fail to make it.


  1. Some other languages have make it.(As I noted before)
  2. Though there are many global functions(such as 'rb_define_method'), but GET_THREAD() can help distinguish different threads so different RubyVM. When these functions are called, they can work on specific RubyVM of the calling thread.
  3. It should be compatible with all existed codes.(I think). including ruby codes and ruby native extensions' codes.(because it do not demand to change any interface)
  4. Each RubyVM can have it's own GC system.
  5. There can be such ruby codes to create new RubyVM on new thread:
vm ="a.rb") #create a new RubyVM on new thread(not run immdiately)
#vm.set_global_variable("$argv", [1, 2, 3]) #wrong! this may cause trouble when GC.
a = [1, 2, 3]
vm.set_global_variable("$argv", a) #right! variable 'a' is managed by the RubyVM on the main thread, new thread do not hold a reference to a
vm.exec #run it
vm.shutdown #shutdown and destroy it

Hope to add this feature in new ruby.

Related issues

Related to Ruby master - Bug #13188: Reinitialize Ruby VM. Rejectedko1 (Koichi Sasada)Actions
Related to Ruby master - Feature #7003: Please decide. MVM to be with 2.0?Rejectedmatz (Yukihiro Matsumoto)09/10/2012Actions

Also available in: Atom PDF