On Dec 23, 2005, at 11:38 AM, Matias Surdi wrote: > 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") On Posix file systems, writes to a file in append mode are atomic but that is only true when you make a direct system call. In Ruby that would be a call to IO#syswrite, which bypasses all the standard buffering of puts and company. You can't mix and match these types of IO calls. It is one or the other. Caveats: I think there is a limit on the size of the write that will guaranteed to be atomic. The Unix system calls pathconf and fpathconf give you access to the PIBE_BUF limit that specifies this limit for *pipes*. I'm not sure if there is a similar limit for files. I just couldn't locate anything specifically in my quick research. Related Question: Does Ruby have its own buffering methodology or does it use the C stdio library buffering for file I/O? I just don't know enough about the Ruby internals to answer this question. Gary Wright