RE: file i/o in multithreaded apps

Tech-Archive recommends: Speed Up your PC by fixing your registry



Hi Mark,

I agree with Pete that the code here looks quite simple and reasonable
which should work well. For the data that got lost, are they written in
some other particular threads which may has some other synchronizing
operations that may cause it to block or not writing correctly? It would be
helpful, if we can simplify it and track down what kind of data are always
lost. BTW, as Pete mentioned, you'd better not lock on the streamwriter
objecct, but use a simple Object member.

Please feel free to post here if there is anything else you found.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

This posting is provided "AS IS" with no warranties, and confers no rights.
-----------------------------
From: =?Utf-8?B?TWFyaw==?= <mmodrall@xxxxxxxxxxxxx>
Subject: file i/o in multithreaded apps
Date: Mon, 7 Apr 2008 14:54:03 -0700

Hi...

I've got an app that's pretty multi-threaded. While I'm debugging, I'm
trying to write a log file of events that happen, so I've got a global
logger
that has
g_LogFileWriter = new StreamWriter(new FileStream(file, Append, Write.
Share.Read);

void Log2File(string format, params object[] arg)
{
lock (g_LogFileWriter)
{
g_LogFileWriter.WriteLine(format, arg);
g_LogFileWriter.Flush();
}
}

Problem is that when things happen very close together and multiple
threads
call this, lines seem to be getting lost. Is there some timing limit on
how
tight many threads can write to the same file stream?

Thanks
Mark



.



Relevant Pages

  • Re: What is "softcock" tennis?
    ... Whisper kirjoitti: ... That Sampras' last slam alone boosted his legacy big time. ... Props for Pete. ... AO 01 lost a close match to Martin who played the ...
    (rec.sport.tennis)
  • a long i/v but worth reading ... for sampras (or tennis for that matter) fans !!
    ... because Pete wanted to play a game of golf in Newport Beach. ... Pete lost his number one spot and his confidence. ... Tim Gullikson had big problems with his health at the ... You had to play a match. ...
    (rec.sport.tennis)
  • Re: Agassi schooling Sampras at FO
    ... Rare to see Agassi kicking Sampras' ass in a slam. ... I imagined Sampras playing in this era meeting Nadal on clay ... but if it was the version who lost to ... titles as Pete - while Pete had the home crowd support. ...
    (rec.sport.tennis)
  • Re: Is Pete the most boring person in tennis history?
    ... I mean Pete seems like a decent enough guy ... single-minded in his pursuit of tennis glory. ... Pete also LOST a LOT of matches. ... Borg OTOH won and almost never lost. ...
    (rec.sport.tennis)
  • Re: Go the Argies!
    ... No way the French are losing this one. ... They've lost the last 4 havent they....Ok the Argies have lost Gaetanbut they still have a decent squad. ... Arg 17 Fra 10 ...
    (rec.sport.rugby.union)