The Problem:
When I ran:
> rails generate rspec:install> rails generate cucumber:install
I got:
[BUG] cross-thread violation on rb_gc() (null) This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.
The Solution:
I found this post in the RubyInstaller google group where Luis Lavena had worked with someone else seeing the same issue, and he recognized it as a problem with the json gem version 1.4.6 x86-mingw32 not having binaries for Ruby 1.9.
His recommended fix, that worked for me, is to run:
> gem uninstall json
Then download and install DevKit for the Ruby installation I was using (I’m using pik and was trying to set up a new environment, see the details below)
Then run:
> gem install json --platform=ruby
And then the rails generate rspec:install and rails generate cucumber:install commands worked as expected.
Please comment if this post helped you with the same issue, or if you know how to fix this issue so that it won’t bite others in the future. I’m still a beginning Rubyist (I’ve gotten to a point where I’m starting to know how much I don’t know), and I’m definitely interested in working on this and other problems (which was my original intention of this evening!!!) but I don’t know exactly how to go about doing such things yet, in many cases.
The Details after the cut.
ETA the search queries I used trying to track this down, in the details.
I’m using pik, the Windows alternative to rvm. My overall goal was to create a new, clean pik environment in which I could create a new rails app using a clean gemset.
So I used the RubyInstaller (thank you again, Luis!) to install Ruby 1.9.2, then I added it to pik and switched to it.
Then I started installing– rails 3.0.3 and cucumber 0.9.4 (the gem I’m interested in reproducing a bug with/patching).
At that point I switched to following The RSpec Book starting on page 286 (of printing 1) which has you do:
> rails new <my-app> > cd <my-app>
Modify your Gemfile to be:
source 'http://rubygems.org' gem 'rails', '3.0.3' gem 'sqlite3-ruby', :require => 'sqlite3' group :development, :test do gem 'rspec-rails', ">=2.0.0" gem 'cucumber-rails', ">=0.3.2" gem 'webrat', ">= 0.7.2" end
Then run:
> bundle install
And then finally:
> rails generate rspec:install
And that is how I got to the cross-thread violation on rb_gc(). Phew.
How I got to the solution:
Google searches for:
- rails generate rspec install bug cross-thread violation
- “cross-thread violation on rb_gc”
- pik ruby windows cross-thread violation rb_gc
- +pik +ruby +windows +cross-thread +violation +rb_gc (yes, google, i really want ALL these terms to be in the pages you give me… what is this, 1997? That’s another post…)
- site:ruby-forum.com “cross-thread violation on rb_gc”
- bug cross-thread violation dll (i had seen a dll having to do with 1.8 being referenced in the details of the crash as reported by windows)
- bug cross-thread violation rb_gc dll
Stack overflow searches for:
- [ruby] [cucumber] cross-thread violation
- [cucumber] cross-thread violation
- [rspec] cross-thread violation
I also looked at the issue trackers for pik and a lot of posts on the Ruby Forum.
I have now learned that the RubyInstaller google group is a good place to start looking for windows+ruby related issues.

Yeah, we had to use that trick for a couple of gems with our compiled-with-VS8 ruby. A bunch of gems thought they had the right binaries, but they didn’t.
I believe you can actually put anything for the platform…if it doesn’t match then it downloads the source and compiles it.
Obviously, in our case, we had the full source so we didn’t need the devkit stuff.
thanks for posting this! helped resolved the error, but with watir-webdriver.
Thanks for the solution :) reinstalling json did the trick.
Thankyou!! Helped with rails g spree:install
BLESS YOU! Was going nuts. I also had to dump sqlite3 for whatever reason.
gem uninstall sqlite3
gem install sqlite3
and all is well.
This fixed it for me. Thanks!
Thank you. Worked for me too. Mac OS 10.8.2, Ruby 1.9.3, JSON 1.7.5.
Thanks very much. Fixed my issue.
obrigado, estava com problemas com meu passenger, nginx, rails 3.2.3 e meu macosx mountain lion e sua solução de desinstalar o gem json foi matador. Ao iniciar o WEBSERVER nginx com passenger, ocorria o erro “[BUG] cross-thread violation on rb_gc()
(null)”, mas após desinstalar o gem json, tudo voltou como deveria ser.
Muito obrigado!!! abraços!!!
obrigado!! :)