<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Le 22/03/2012 16:20, Mattias Gaertner a écrit :
    <blockquote
cite="mid:17685495.299920.1332429617197.JavaMail.open-xchange@comcenter.netcologne.de"
      type="cite">
      <meta content="text/html; charset=ISO-8859-1"
        http-equiv="Content-Type">
      <p style="margin: 0pt;"> <span> <span></span> </span> </p>
       
      <p style="margin: 0px;">Each thread has its own stack.</p>
      <p style="margin: 0px;">All threads share the same address space
        and the same heap.</p>
      <p style="margin: 0px;">Objects (here: class instances) are
        created on the heap. The heap is thread safe. </p>
      <p style="margin: 0px;">The data segment is for constants. They
        are shared. </p>
    </blockquote>
    Le 22/03/2012 17:10, Michael Schnell a écrit :
    <blockquote cite="mid:4F6B4F0C.4070801@lumino.de" type="cite">Besides

      what the other said a very basic comment. <br>
      <br>
      The location where an object is defined (i.e. within a TThread
      enabled unit) or who created it (the main line code or the thread
      code) does not matter. The Concept of classes, objects and
      instances is a matter of memory allocation and pointers and not a
      concept of program flow. same is absolutely independent. You can
      use one instance of a class in one thread and another one in
      another thread. You can create an instance in one thread and call
      its procedures and properties by another one. (BTW this results in
      the fact that its very hard to define something like "Thread-safe"
      for a class). <br>
    </blockquote>
    Thanks to you all .<br>
    Trying to be as much clear as possible, there are some sentences:<br>
    <br>
    Assuming this few statements (aka my own rules when writing thread's
    code):<br>
    a. all thread code+data are encapsulated into a TThread object<br>
    b. "Thread safe" means that there is no overlap of data references
    from thread to thread, the main thread inclusive, and that no
    references are passed outside the thread's control from thread to
    thread (by the means of the owner or global vars for instance)<br>
    c. the thread creator does not interfere in any way with the
    thread's data and methods as soon as the thread has been started
    (Terminated execpted of course)<br>
    d. no function neither procedure calls are made to any function or
    procedure defined outside of the thread control (aka self defined
    methods)<br>
    <br>
    Do you all agree on the following asserts:<br>
    1. All variables in the thread definition (TThread's private,
    protected and public variables) are "Thread safe" BUT are accessible
    to the thread creator<br>
    2. an instance of an object (aka TObject descendant) created into
    the thread's EXECUTE procedure is invisible to all other instances 
    of the same object whichever the creator could be (the same thread
    or other threads created with the same thread definition object) and
    to other thread object instances, even when the reference variable
    of the created object is defined into the thread vars (see 1.)
    provided that all object methods do not call any function or
    procedure outside of the object methods.<br>
    3. all variables described in the VAR part of the EXECUTE procedure
    are "Thread safe" (seems obvious) <br>
    4. all local variables and constants defined into local Thread
    object methods are "Thread safe" (they are defined into each thread
    stack for the vars and the heap for constants)<br>
    5. all useful code a thread needs should be encapsultated into a
    TObject descendant and instantiated within the thread's space.<br>
    6. all methods defined in the thread's definition, aprat from the
    EXECUTE procedure (obvious !), run into the  thread creator space
    (the one which instantiates the thread, aka does something like
    wThread := TMyThread.Create (False) )<br>
    <br>
    This list is (certainly) not exhausted.<br>
    <br>
    Antonio.<br>
    <br>
    <br>
  </body>
</html>