By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,887 Members | 1,170 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,887 IT Pros & Developers. It's quick & easy.

multiple threads updating same log file

P: n/a
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?
Feb 14 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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
"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?

Feb 15 '06 #2

P: n/a
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:%2****************@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?
Feb 15 '06 #3

P: n/a
cj
I think that's what I'm going to do.
José Manuel Agüero wrote:
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:%2****************@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?

Feb 15 '06 #4

P: n/a
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/de...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.

Feb 16 '06 #5

P: n/a
cj
I got it. Thanks.
Peter Huang [MSFT] wrote:
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/de...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.

Feb 16 '06 #6

P: n/a
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.

Feb 17 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.