I don't know what you're trying to do but couldn't you remove the possible problem by giving each thread its own file handle?