Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You'd better not. Thread objects are exactly made to insulate its variables from other threads.<br> Otherwise all kind of random non-reproducible errors would appear - <a href="http://en.wikipedia.org/wiki/Heisenbug" rel="nofollow">http://en.wikipedia.org/wiki/Heisenbug</a></p> <p><a href="http://en.wikipedia.org/wiki/Parallel_programming" rel="nofollow">Parallel programming</a> should have very clear separation and insulation. Because You can never predict the timing of execution and which statement would run earlier and which one later.</p> <p>Imagine that easy scenario:</p> <pre><code> ws := TIdTCPClient.Create(nil); ws.Host := Fff_host; // at this point another thread gets access to ws variable, // as You demanded - and changes it, so WS gets another value! ws.Port := Fff_port; </code></pre> <p>How would you detect such a bug, if it happens only on client multi-processor computer under heavy load once a month ? In your workstation during debug sessions or simulation it would not be reproduced ever! How would you catch it and fix ?</p> <p>As a rule of thumb, when doing parallel programming the data should be spleat into "shared immutable" and "private mutable" pieces, and when doing inter-thread communication you should - similar to inter-process communications - make some events/messages queue and <a href="http://en.wikipedia.org/wiki/Actor_model" rel="nofollow">pass commands and replies</a> to/from threads, like it is done in Windows GDI or like in MPI</p> <p>Then you thread would fetch "change ws variable" command from queue - in the proper moment when the change is allowed - and change it from inside. Thus you would assume control and assure that variables are only changed in that point and in that manner, that would not derail the code flow.</p> <p>I suggest you to read OTL examples to see how inter-thread communication is done in more safe way that direct access to objects. <a href="http://otl.17slon.com/tutorials.htm" rel="nofollow">http://otl.17slon.com/tutorials.htm</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload