From: Joel VanderWerf Date: 2005-10-09T01:26:48+09:00 Subject: Re: Save the world from evil code crusade Joel VanderWerf wrote: > aurelianito wrote: > >>I want to say things like evil.rb code can write to "evil.log" but to >>nothing else. >>How can use threads to say this kind of things with threads? >> > > > require 'thread' > > write_queue = Queue.new > > safe_thread = Thread.new do > $SAFE = 4 > data = "some data" > write_queue << data > end > > > write_thread = Thread.new do > loop do > data = write_queue.pop If you have no control over this data object, you probably want to check that it really is a String (and not some spoofed string with a dangerous #to_s method). > puts data # or write to "evil.log" > end > end > > sleep 0.1 > -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407