Do I need to call Terminate, or does the thread terminate itself, when it is done with it's task?
In the examples, an event is realeased in the destroy method.
(http://wiki.lazarus.freepascal.org/Multithreaded_Application_Tutorial)
Is this a problem in Pascal? Like it can cause memory leak in other programs, if an event is not freed from an object, before the objet is disposed?
About the Event - it is section of Initialization and Finalization...1. Create is a constructor, not a procedure.
So when I free an object, Events can still call none-existing handlers..
Not much actual documentation on how to use it.
I figure it is manly for messaging across Threads.
I wrote the most simplest TThread program for personal notes, this is a command-line example as it is the easiest to understand what's going on. If you use threads in a GUI program you do not need to call CheckSynchronize. http://tech406.com/kdocs/threads.xml
Your code touches the thread outside SayHello:What is the recommended way of checking outside a thread of a thread has finished? I will update my personal notes to reflect this.
Sorry, I should have explained more. The problem is not with calling Finished, it is the fact that you used:Ah, thank you so much for the clarification. That makes complete sense now. I will update the example code in my documentation to reflect the FreeOnTerminate change, and manually Free the thread.
FreeOnTerminate:=True;
I had a hunch WriteLn wasn't thread-safe, as stdout does mangle in Python if used within a thread as well. WriteLn should only be called from the main thread.You can execute it inside a critical section.
I will also make mention that using WriteLn in this example is solely for example purposes to show the thread starting, running, and stopping. I had a hunch WriteLn wasn't thread-safe, as stdout does mangle in Python if used within a thread as well. WriteLn should only be called from the main thread.Writeln to StdOut itself is threadsafe, but the output to the shell will nevertheless likely be mangled.