Recent

Author Topic: TThread questions  (Read 1358 times)

garlar27

  • Hero Member
  • *****
  • Posts: 597
Re: TThread questions
« Reply #15 on: June 04, 2019, 09:57:12 pm »
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.

mr-highball

  • Jr. Member
  • **
  • Posts: 59
Re: TThread questions
« Reply #16 on: June 04, 2019, 11:42:25 pm »
A simple to use reference counted solution that you may want to look at OP is ezthreads. It lets you define the thread's behavior and settings (timeout, etc..)  in a fluent way, and comes with Await functionality similar to c#

I've written some previous posts here:
https://forum.lazarus.freepascal.org/index.php/topic,44274.msg311176.html#msg311176
-Highball

PascalDragon

  • Hero Member
  • *****
  • Posts: 515
  • Compiler Developer
Re: TThread questions
« Reply #17 on: June 05, 2019, 02:06:24 pm »
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.