From: James S. <jam...@op...> - 2006-10-31 20:57:30
|
Hi All, I guess this may not be quite on topic, but some may have run into this before... Recently I wanted to capture debug info from 2 threads of a program written for Windows (compiled with MinGW). As the data was transmit and receive messages (from the 2 threads respectively) I thought I'd just open the same file in each thread and fflush after each fprintf. The result of this was garbled mess. Often one threads data would all be at the head of the file and the other at the tail. The desired result of course was messages interleaved as in tx, rx, tx, rx, etc. So I thought well maybe it's the stream buffering that's affecting it. So I turned buffering off and the result was as bad. Then I tried opening a file with _open (instead of fopen) to do raw writes to it. Also with a '_commit' call after the writes the result was the same as before! What would you expect the results to be if the program was run on a *nix like OS? Should what I was trying to achieve have worked? I have never needed to write threaded programs before, so maybe this is my thread naivety showing through? Regards, James. |