Recent

Author Topic: Question on non-platform-dependent communication between treads  (Read 5735 times)

stab

  • Full Member
  • ***
  • Posts: 234
Hi all,

In windows I've been using windows messages to communicate between background threads and GUI-parts, sending a messageobject containing three parts:
 command, parameters : string; memStream : TMemoryStream.

How could that be expanded to work non-platform-dependent?

Regards
Staffan %)

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4468
  • I like bugs.
Re: Question on non-platform-dependent communication between treads
« Reply #1 on: June 12, 2010, 08:22:09 am »
In windows I've been using windows messages to communicate between background threads and GUI-parts, sending a messageobject containing three parts:
 command, parameters : string; memStream : TMemoryStream.

How could that be expanded to work non-platform-dependent?

In most situations TThread.Synchronize is good enough for updating GUI in main thread. The function is then executed in main thread.
For more complicated situations you can use for example TCriticalSection or some semaphore class.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

stab

  • Full Member
  • ***
  • Posts: 234
Re: Question on non-platform-dependent communication between treads
« Reply #2 on: June 12, 2010, 09:30:09 am »
Thanks for answering,

Think I would stick to critical sections, but I wonder to what extent that is crossplattform.

Regards
Staffan %)

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4468
  • I like bugs.
Re: Question on non-platform-dependent communication between treads
« Reply #3 on: June 12, 2010, 09:50:20 am »
Think I would stick to critical sections, but I wonder to what extent that is crossplattform.

syncobjs.TCriticalSection is crossplatform. You can search Lazarus / LCL source to see how it is used.

There is also a Windows compatible TCriticalSection in LCLType but don't use it.

That is my understanding of things. I didn't use (yet) critical sections with FPC / Lazarus myself.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

stab

  • Full Member
  • ***
  • Posts: 234
Re: Question on non-platform-dependent communication between treads
« Reply #4 on: June 12, 2010, 12:08:50 pm »
Thanks for your comment on syncobjs.TCriticalSection beeing crossplatform

Staffan  ::)

Laksen

  • Hero Member
  • *****
  • Posts: 745
    • J-Software
Re: Question on non-platform-dependent communication between treads
« Reply #5 on: June 13, 2010, 10:40:27 am »
TRTLCriticalSection is also crossplatform. It's part of the threading code in the system unit. It's pretty much identical to the Delphi version

 

TinyPortal © 2005-2018