Skip to content

Instantly share code, notes, and snippets.

@pond
Created May 6, 2014 02:11
Show Gist options
  • Save pond/4c2feec7200c557d69fc to your computer and use it in GitHub Desktop.
Save pond/4c2feec7200c557d69fc to your computer and use it in GitHub Desktop.
#$ rails new foo
#$ cd foo
# <set up config/database.yml to use Postgres with "pool: 1">
# development:
# adapter: postgresql
# encoding: utf8
# database: foo_development
# pool: 1
# <add "gem 'pg'" to Gemfile>
#$ bundle install
#$ rake db:drop; rake db:create; rake db:migrate
#$ rails generate scaffold post title body:text published:boolean
#$ rails c
# <Do a few Post.create!(title:"hello", body:"world")>
# <Then...>
finished=[]
1.upto(2) do |i|
finished[i]="."
Thread.new do
puts "THREAD START #{i} #{Thread.current.inspect}"
1.upto(50) do
Post.first.reload
Post.last.reload
end
print "THREAD DONE #{i} #{Thread.current.inspect}: "
finished[i]="*"
puts finished.join('')
# COMMENT THIS OUT and only 1 thread gets to finish.
# LEAVE THIS IN and both threads finish.
ActiveRecord::Base.connection_pool.disconnect!
end
sleep(1)
puts "COUNT DONE #{i}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment