On Dec 23, 2005, at 12:12 PM, Jellen wrote: > Well, I think it's OK to do that. > Seeing is believing: > # first one > a = Thread.new do > 5.times do > f = File.new("qq.txt", "a").puts "I am a..." > f.close if f > end > end > b = Thread.new do > 5.times do > f = File.new("qq.txt", "a").puts "I am b..." > f.close if f > end > end > a.join > b.join > > # and this one > f = File.new("test.txt", "a") > a = Thread.new do > 5.times do > f.puts "I am a..." > sleep 1 > end > end > b = Thread.new do > 5.times do > f.puts "I am b..." > sleep 1 > end > end > a.join > b.join > f.close > > > Both program are ok. (But I am not sure myself:) Interesting examples, Jellen, but I don't think it answers Matias' question, which was > File.new('filename','a').puts("this is the string") > > > Is this already thread safe??? how can I make it so????? Correct me if I'm wrong, but your examples only prove that the thread on the CPU will be able to append the file. I *think* Matias wants to know if the statement ( File.new('filename','a').puts("this is the string") ) is atomic. Or in other words, do you need to enforce mutual exclusive access to the file with a mutex? Unfortunately, I don't have an answer to that question.