in reply to Threads and output files (locking)
Thanks for your answer. That tutorial was one of the ones I had already read.
I admit the code I posted wasn't very good. I tried to simplify my code, but the result didn't run by itself.
Using a semaphore helps, but there is still a lot of garbled output.
I think part of the problem may be NFS, as mentioned in the File Locking tutorial. The output file on which I place the lock is in my home directory, which is mounted on all the cluster computers.
I tried using File::NFSLock and File::SharedNFSLock, and ran some tests. Sometimes one module does better, sometimes the other, but none achieves 100%. In the best case, at least 100 out of 22000 lines are still jumbled together.
So I guess I will have to go back to my previous approach, in which I printed the data to a bunch of files containing four lines each, and then postprocess the whole thing by concatenating them, sorting and grep'ping for the right lines to separate the output into the four desired output files.
Oh well. At least I learned something in the process :-)
|
|---|