Mega Search
23.2 Million


Sign Up

Make a donation  
Is TIdUDPClient.SendBuffer thread safe?  
News Group: embarcadero.public.cppbuilder.internet.socket

Hi all.

Indy 10.

I used TIdUDPClient.SendBuffer in thread in general VCL manner as
non-thread safe (via Synchronize).

Now I need to post from thread immediately. Is TIdUDPClient.SendBuffer
thread safe (if I don't change properties of course)?

-- 
Alex

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 28-Aug-2011, at 4:04 AM EST
From: Alex Belo
 
Re: Is TIdUDPClient.SendBuffer thread safe?  
News Group: embarcadero.public.cppbuilder.internet.socket
"Alex Belo"  wrote in message 
news:392691@forums.embarcadero.com...

> I used TIdUDPClient.SendBuffer in thread in general
> VCL manner as non-thread safe (via Synchronize).
>
> Now I need to post from thread immediately. Is
> TIdUDPClient.SendBuffer thread safe (if I don't
> change properties of course)?

Are you using the TIdUDPClient object in multiple threads?  SendBuffer() 
accesses the Binding property internally.  Although sending data does not 
need to be synchronized, the Binding property getter, which allocates the 
socket, is not thread-safe.  At the very least, if you activate the 
TIdUDPClient (set its Active property to True, which allocates the Binding) 
before any threads access it, then you should be ok.

-- 
Remy Lebeau (TeamB)

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 28-Aug-2011, at 1:34 PM EST
From: Remy Lebeau (TeamB)
 
Re: Is TIdUDPClient.SendBuffer thread safe?  
News Group: embarcadero.public.cppbuilder.internet.socket
Hi Remy.
Thank you for answering.

Remy Lebeau (TeamB) wrote:

> > I used TIdUDPClient.SendBuffer in thread in general
> > VCL manner as non-thread safe (via Synchronize).
> > 
> > Now I need to post from thread immediately. Is
> > TIdUDPClient.SendBuffer thread safe (if I don't
> > change properties of course)?
> 
> Are you using the TIdUDPClient object in multiple threads?

No in fact. All TIdUDPClient properies/methods are used in Synchronize.

> SendBuffer() accesses the Binding property internally.  Although
> sending data does not need to be synchronized, the Binding property
> getter, which allocates the socket, is not thread-safe.  At the very
> least, if you activate the TIdUDPClient (set its Active property to
> True, which allocates the Binding)

I set Active=True at design time.

> before any threads access it, then you should be ok.

Many thanks for information, it will be useful in future (because I've
rethought my design and need not avoid call of Synchronize now).

Are such details documented? I mean that sending from different threads
is usual task, so (despite the fact that Indy is VCL-style library)
Indy components should support it at least in some low level methods on
some conditions (like Active=True in our case).

-- 
Alex

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 28-Aug-2011, at 9:26 PM EST
From: Alex Belo
 
Re: Is TIdUDPClient.SendBuffer thread safe?  
News Group: embarcadero.public.cppbuilder.internet.socket
"Alex Belo"  wrote in message 
news:392879@forums.embarcadero.com...

> Are such details documented?

Not specifically, no.  Indy is designed for threading, that is part of its 
core design, but that does not mean you can throw away thread safety 
altogether.

-- 
Remy Lebeau (TeamB)

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 29-Aug-2011, at 1:49 AM EST
From: Remy Lebeau (TeamB)
 
Re: Is TIdUDPClient.SendBuffer thread safe?  
News Group: embarcadero.public.cppbuilder.internet.socket
Remy Lebeau (TeamB) wrote:

> > Are such details documented?
> 
> Not specifically, no.  Indy is designed for threading, that is part
> of its core design, but that does not mean you can throw away thread
> safety altogether.

No, I don't intend throw away thread safety altogether. :)

I'm just saying that it would be nice to document what methods and
under what conditions are thread-safe (like: "TIdUDPClient.SendBuffer
is thread-safe if Active=true before any threads access it"). IMHO this
information is important for everyone.

-- 
Alex

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 29-Aug-2011, at 2:40 AM EST
From: Alex Belo