473,791 Members | 2,853 Online
Bytes | Software Development & Data Engineering Community
+ 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 5108
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.nosp am> escribió en el mensaje news:%2******** ********@TK2MSF TNGP11.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.nosp am> escribió en el mensaje news:%2******** ********@TK2MSF TNGP11.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
11218
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 multiple threads, how would I solve that? thanx,
6
3206
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 list within a single object, which is then placed on a stack(This cuts down thread creation and deletions roughly by a factor of 4). I create up to 12 threads, which then process a single object off of the stack. I use a loop with a boolean...
4
5301
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 time a thread try to do something with the file, the thread will create a new file handle. However, if I specify FileShare.ReadWrite, other process can also open that file. I tried FileShare.Inheritable but it doesn't work. The reason I needs to...
6
5000
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 for long running reports. When the processing is complete it uses crystal reports to load a template file, populate it, and then export it to a PDF. It works fine so far....
6
4073
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 lost. So i have to provide some lock mechanism to that file in ftp, so how can i lock it, if one client opens it for updating, so that till it gets relased it cannot be updated by other clients. Could u please suggest me the simple solutions...
4
1978
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 an example of multiple threads synchronized to use a single shared resource? -- Gregory Gadow
35
9366
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 500000 to 3200000 of a file whose size is say 20MB... how do i request a download which starts directly at 500000th byte... thank u cheers
2
11327
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 files, can call custom code for each file received - much like BizTalk) 1. Receive multiple files, each file received creates a "WriteToFile" object
16
15570
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 faster, so I'd like to try creating multiple threads, and having them load different chunks of the file at the same time and process it asynchronously. Is it possible to do something like that, and if so, what would be needed to do so?
0
9669
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10426
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5430
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4109
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 we have to send another system
2
3713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.