is it safe to use methods and properties inside a thread

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
inageib
Posts: 184
Joined: Wed 26 Aug 2009 14:11

is it safe to use methods and properties inside a thread

Post by inageib » Tue 07 May 2013 22:33

Hi,
I want to ask is it safe to call methods and read or change properties values of components like TIBCQuery, TIBCSQL, TIBCStoredProc, etc... from inside a thread other than the main app thread ?

Thanks

AndreyZ

Re: is it safe to use methods and properties inside a thread

Post by AndreyZ » Wed 08 May 2013 13:18

Hello,

You can safely read properties, but writing properties and calling methods may cause numerous errors which are hard to trace. For example, if you use some code in the main thread that depends on some property value, and at the same time you change this property value in another thread, the code in the main thread may have an unexpected behaviour. The same applies to calling methods. Therefore, you should not access the same component from different threads. If you want to do this, you should ensure thread safety on your own.

inageib
Posts: 184
Joined: Wed 26 Aug 2009 14:11

Re: is it safe to use methods and properties inside a thread

Post by inageib » Fri 10 May 2013 23:49

I am asking specially if I called execute from within a thread

Code: Select all

<TIBCSQL>.Execute
But also in the main thread I use execute with same component but both not called at same time, as the user need to open a form and press a button in this time the first thread would be finished executing. in addition I can check it the thread is terminated or not. do you think in this case a conflict may still occur ?

AndreyZ

Re: is it safe to use methods and properties inside a thread

Post by AndreyZ » Mon 13 May 2013 13:32

In the situation you described it is safe to call the TIBCSQL.Execute method from the thread.

inageib
Posts: 184
Joined: Wed 26 Aug 2009 14:11

Re: is it safe to use methods and properties inside a thread

Post by inageib » Tue 14 May 2013 16:32

Thanks Andrey

AndreyZ

Re: is it safe to use methods and properties inside a thread

Post by AndreyZ » Wed 15 May 2013 10:05

I am glad to help.

Post Reply