Home All Groups Group Topic Archive Search About

multiple threads updating same log file

Author
14 Feb 2006 9:32 PM
cj
As many of you know I'm writing a TCP/IP server with multiple threads
handling multiple short conversations (submit a short string, send back
a sort string).  Threads are created as needed to handle a new
connection request and terminate after the exchange is complete.

I got a new request for the program.  I've been asked the the program
write all the strings it receives and sends to a log file.  I'm
concerned about all these threads stepping on each other writing to a
common file.  Any ideas?

Author
15 Feb 2006 1:05 AM
Dennis
Can you use a "busy" variable as a flag and set to true when writing then
false when not writing.  Should be able to control the simultaneous writing
using Synclock on the flag.
--
Dennis in Houston


Show quoteHide quote
"cj" wrote:

> As many of you know I'm writing a TCP/IP server with multiple threads
> handling multiple short conversations (submit a short string, send back
> a sort string).  Threads are created as needed to handle a new
> connection request and terminate after the exchange is complete.
>
> I got a new request for the program.  I've been asked the the program
> write all the strings it receives and sends to a log file.  I'm
> concerned about all these threads stepping on each other writing to a
> common file.  Any ideas?
>
Author
15 Feb 2006 3:06 PM
José_Manuel_Agüero
Hello cj,

You can create a single class that writes the log file. This class must be thread safe through synchronization mechanisms. Then your threads can use that class to write to the log.

Regards.


Show quoteHide quote
"cj" <cj@nospam.nospam> escribió en el mensaje news:%23bBdy4aMGHA.2320@TK2MSFTNGP11.phx.gbl...
| As many of you know I'm writing a TCP/IP server with multiple threads
| handling multiple short conversations (submit a short string, send back
| a sort string).  Threads are created as needed to handle a new
| connection request and terminate after the exchange is complete.
|
| I got a new request for the program.  I've been asked the the program
| write all the strings it receives and sends to a log file.  I'm
| concerned about all these threads stepping on each other writing to a
| common file.  Any ideas?
Author
15 Feb 2006 3:26 PM
cj
I think that's what I'm going to do.


José Manuel Agüero wrote:
Show quoteHide quote
> Hello cj,
>
> You can create a single class that writes the log file. This class must be thread safe through synchronization mechanisms. Then your threads can use that class to write to the log.
>
> Regards.
>
>
> "cj" <cj@nospam.nospam> escribió en el mensaje news:%23bBdy4aMGHA.2320@TK2MSFTNGP11.phx.gbl...
> | As many of you know I'm writing a TCP/IP server with multiple threads
> | handling multiple short conversations (submit a short string, send back
> | a sort string).  Threads are created as needed to handle a new
> | connection request and terminate after the exchange is complete.
> |
> | I got a new request for the program.  I've been asked the the program
> | write all the strings it receives and sends to a log file.  I'm
> | concerned about all these threads stepping on each other writing to a
> | common file.  Any ideas?
Author
16 Feb 2006 2:39 AM
Peter Huang" [MSFT]
Hi

Also I think as Dennis suggest, we can use the threading synchronize
mechanism to make sure there will be only one thread access to the log file
in the meantime.
You may take a look at the link below.
SyncLock Statement
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbls7/html/
vblrfvbspec8_5.asp


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Author
16 Feb 2006 1:26 PM
cj
I got it.  Thanks.


Peter Huang [MSFT] wrote:
Show quoteHide quote
> Hi
>
> Also I think as Dennis suggest, we can use the threading synchronize
> mechanism to make sure there will be only one thread access to the log file
> in the meantime.
> You may take a look at the link below.
> SyncLock Statement
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbls7/html/
> vblrfvbspec8_5.asp
>
>
> Best regards,
>
> Peter Huang
> Microsoft Online Partner Support
>
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
Author
17 Feb 2006 2:13 AM
Peter Huang" [MSFT]
Hi

You are welcomed!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.