Created
December 3, 2008 14:32
-
-
Save NZKoz/31564 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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