multiple threads updating same log file

  • Thread starter Thread starter cj
  • Start date Start date
C

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?
 
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.
 
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" <[email protected]> escribió en el mensaje | 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?
 
Back
Top