Board index » delphi » team indy: simultaneous write

team indy: simultaneous write

Hi

What will happend if I have two threads which both write to the same
tcpclient at the same time. Will the data get mixed up ? should I use a mutx
or critical region to protect the write ?

 

Re:team indy: simultaneous write


Quote
> What will happend if I have two threads which both write to the same
> tcpclient at the same time.  Will the data get mixed up ?

Yes, you will.

Quote
> should I use a
> mutx or critical region to protect the write ?

Yes, you should. Alternatively, you could use a communication queue: it's
basically a thread-safe FIFO queue. The sender threads pushes data packets
to the queue while the reader thread pull them and send them to the remote
client. This allows you to sustain an optimal transfert rate (as long as
there is data in the queue, the bandwisth is used at it's full capacity and
adding more data does not block the sending of buffered data).

Good luck,
stephane

Other Threads