[Lazarus] thread safe

Hans-Peter Diettrich DrDiettrich1 at aol.com
Sat Jun 11 03:41:03 CEST 2011


Henry Vermaak schrieb:

>> What is "thread safe"?
> 
> The definition is very clear here:
> 
> http://en.wikipedia.org/wiki/Thread_safety

It is not really clear:

"A piece of code is thread-safe if it can be safely invoked by multiple
threads at the same time".

Which piece of code can *not* be "safely invoked"?

Instead I'd define "thread safety" as the *absence* of possible data or
state inconsistencies in concurrent execution [of threads].

As mentioned in most articles "It is not easy to determine if a piece of
code is thread-safe or not". That's why I wonder how a subroutine (piece
of code) can be said to be thread-safe, without indicating the really
asserted behaviour and possible limitations.

E.g. QueueAsyncCall may be "safely invoked", but what will happen later,
when e.g. the referenced object is destroyed prior to the according
Deque? The caller will never be notified of the outcome of the call! How
can the caller check, after posting an call, that the operation has
executed or has been dropped? When will it be *safe* to release the Data 
object, that possibly has been passed to the callee? That's why I'm 
missing at least a note, that the queued call may never execute, and 
that passing pointers for Data is unsafe.

Okay, it may be beyond the scope of QueueAsyncCall, to establish means 
for synchronization between the caller and the callee. But what could be 
done to allow for such synchronization?

DoDi





More information about the Lazarus mailing list