gwtmp01 / mac.com wrote:
> 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")

Apart from MT issues this code has serious different issues: you do not 
close the file (and you cannot because the IO is not returned from puts). 
You rather want

File.open('filename','a') {|io| io.puts("this is the string")}

Otherwise you risk that the text is not written to the file in the proper 
order - or you get even problems opening the file multiple times.

There are two possible solutions: synchronize every access to a file or use 
a Queue and a separate writing thread (might be better performance wise, 
because you don't have to reopen the file all the time).

Kind regards

    robert