|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
multiple threads updating same log fileAs 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? 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. -- Show quoteHide quoteDennis 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? > 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? 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? 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. 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. > 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. |
|||||||||||||||||||||||