<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
On 06/27/2011 12:51 PM, Martin wrote:
<blockquote cite="mid:4E0860CB.2070504@mfriebe.de" type="cite">
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<br>
Why? Where does the definition conflict with the above?<br>
"A piece of code is <b>thread-safe</b> if it can be safely
invoked by multiple threads at the same time"<br>
</blockquote>
It does not <b>conflict</b> it is just not useful.<br>
<br>
The problem is not "safe invocation" the problem is "<b>a</b> piece
of code".<br>
<br>
An object is invocated with a hidden self pointer. So for the "user"
this "self" is not an "input" as normal parameters are. <br>
<br>
By definition, an object is a combination of a data store and a pool
of functions. <br>
<br>
Thus (when looking at your definition above) you either can define
that (A) the the "code" is <b>different</b> for multiple instances
of the object (even though it only exists once in memory and in the
source code), or you can define or you can define that (B) it's <b>the
same piece of code</b> for all instances.<br>
<br>
From the point of view of the user both does make sense (if you get
him to be aware of that at all). <br>
<br>
Obviously as an example, the (non-thread-safe) TList.add
(supposedly) can happily be used with multiple threads if each
thread uses it's own instance and thus different code (regarding
definition (A), while TThreadList is thread safe (regarding both
definitions) and the same instance can be used by multiple threads.
<br>
<br>
The reason is, that TList just uses (stack and) class variables (and
decently protected global variables), While with TThreadList
additionally the class variables are decently protected.<br>
<br>
OTOH, e.g. TForm is not thread save at all: you can't do multiple
instances and use each of them from it's dedicated thread, because
implicitly TForm uses unprotected global variables. <br>
<br>
-Michael<br>
<br>
</body>
</html>