[Lazarus] thread safe
mschnell at lumino.de
Fri Jun 10 16:17:15 CEST 2011
On 06/10/2011 04:01 PM, Reimar Grabowski wrote:
>> threads call it with the same parameter.
> These kind of functions are called not thread safe.
That is exactly what I wanted to say. (With Objects this is more obscure
than with the ANSI C code example, as the instance parameter is hidden
and the application programmer usually is not aware if same.)
Regarding objects this definition does not make much senses, as this
would make make most objects non thread safe, while they would be
thread-safe if each thread uses it's dedicated instance.
Thus a more sophisticated definition of thread safety for objects makes
a lot more sense that simply stating that practically all objects are
not thread safe, even though the practical use of a class could be to be
have an instance used by a single thread.
TThreadList is "completely thread safe".
TList is (supposedly) "per-instance thread safe": the "TThread.Add"
"piece of code" can happily be used by multiple threads at the same
time, as long as each thread uses a different instance. I suppose this
is done quite often.
More information about the Lazarus