Matias Surdi <matiassurdi / gmail.com> writes: > Hi... > > I've a class which is run by many threads at the same time.... this > class has to append a line to a text file eventually. > > I do this with: > > File.new('filename','a').puts("this is the string") Don't do this. It's not an atomic operation, either with buffered or unbuffered IO. > Is this already thread safe??? No. > how can I make it so????? If thread A outputs two line, and thread B outputs one line, would this be acceptable? A-1 B-1 A-2 Or should it be: A-1 A-2 B-1 How granular do you want it? Per line? Per thread output? Please investigate the mutex library. file_mutex.synchronize { file.puts(".....") file.puts(".....") } YS.