Skip to content

Instantly share code, notes, and snippets.

@NZKoz
Created December 3, 2008 14:32
Show Gist options
  • Save NZKoz/31564 to your computer and use it in GitHub Desktop.
Save NZKoz/31564 to your computer and use it in GitHub Desktop.
require 'thread'
class BuggeredLogger
def initialize
@buffer = []
@mutex = Mutex.new
end
def maybe_flush
flush if @buffer.size > 10
end
def flush
return unless @buffer.size > 0
@mutex.synchronize do
puts "*** #{@buffer.slice!(0..-1).size}"
end
end
def log(msg)
# Have to log appends too, otherwise jruby dies
@mutex.synchronize do
@buffer << msg
end
maybe_flush
end
end
$logger = BuggeredLogger.new
threads = (1..50).map do |i|
Thread.new do
loop do
$logger.log("HEY MAN, I AM #{i}")
puts "logged from #{i}"
end
end
end
# run the hax for 60 seconds
sleep(30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment