<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote"><div class="im"><div><br></div></div><div>Yeah, this is what I do with debugging statements. I'd like to put individual log lines/entries out to the file system rather than the console. Given that posix requires stdio operations dealing with FILE* structures to work atomically, do you think fprintf calls are a reasonable thing to do in a multi-threaded driver?. </div>
<div class="im">
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></blockquote></div><br><div>This seems like an inane question. What I'm getting at is that I've seen plenty of driver code which writes to a file like this only when protected by a driver mutex. I'm guessing that this is because they are pushing multiple lines/writes out in one go and want to avoid interleaving the output when many threads simultaneously call the write/log function. </div>
<div><br></div><div>Now I don't care about this interleaving as all my logging statements fit in a single (s)printf call and I couldn't care less about the order in which they appear in the log - the thread id is there to disseminate this information later on. I'm under the impression that posix compliant systems will ensure that the single write (and therefore individual log lines) are written atomically. Have I got this right and is this is reasonable assumption to make - it feels like no, but I'm being over cautious as I don't know the answer and don't want to write useless driver code. I'd also like to avoid excessive locking if it's not necessary and certainly avoid excessive communication between the driver and the emulator just for logging.</div>
<div><br></div><div>Can anyone clear this up for me? Is there a Right Thing To Do (TM) in this situation? </div>