Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.