473,466 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

multiple threads updating same log file

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
6 5091
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Guyon Morée | last post by:
If I have multiple threads reading from the same file, would that be a problem? if yes, how would I solve it? Let's say I want to take it a step further and start writing to 1 file form...
6
by: m | last post by:
Hello, I have an application that processes thousands of files each day. The filenames and various related file information is retrieved, related filenames are associate and placed in a linked...
4
by: Tony Liu | last post by:
Hi, how can I create multiple new file handles of a file without having to share to file to the other processes? I have a file that will be accessed by multiple threads in my application, each...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
6
by: muttu2244 | last post by:
hi all am updating the same file in ftp, through multiple clients, but am scared that two clients may open the same file at a time, and try updating, then the data updated by one data will be...
4
by: Gregory Gadow | last post by:
I've cobbled together a PrinterClass that takes a text file and dumps it to a printer. The app using is has multiple threads, all of which need access to a shared instance. Can someone point me to...
35
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from...
2
by: =?Utf-8?B?RGFtZW9u?= | last post by:
Hi - I am attempting to write lines to a file at high volume, multiple threads. Here is my scenario: (initial "WriteToFile" object created via a parent multithreaded process, which receives...
16
by: WATYF | last post by:
Hi there... I have a huge text file that needs to be processed. At the moment, I'm loading it into memory in small chunks (x amount of lines) and processing it that way. I'd like the process to be...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.