Skip to content

Instantly share code, notes, and snippets.

@phiggins
Created June 2, 2010 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phiggins/421984 to your computer and use it in GitHub Desktop.
Save phiggins/421984 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'sequel'
require 'fileutils'
require 'logger'
db_file = '/tmp/delete_me.sqlite'
FileUtils.rm( db_file ) if File.exists?( db_file )
DB = Sequel.sqlite( db_file )
logger = Logger.new( "/tmp/threaded_test.log" )
DB.loggers << logger
DB.create_table :things do
primary_key :id
Integer :n
Time :created_at
end
class Thing < Sequel::Model
plugin :timestamps
end
N = 25
things = (0..N).map do |n|
Thing.create( :n => n )
end
threads = [0,1].map do |i|
Thread.new do
i.step(N, 2) do |j|
thing = things[j]
thing.n += 1
thing.save
end
end
end
threads.each {|t| t.join }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment