In this scenario, without knowing anything else about the problem, I would set up one thread as the 'File Writer' thread and a shared buffer (or a threaded object... not sure what kind of programming environment you're in).
Assuming you're in a C environment and using a shared buffer, protect it with a semaphore. Every time you write to it, post to the semaphore. Have the file writer thread pending on the semaphore and then empty the buffer into the appropriate section of the file.
Hope this helps, Cheers.