Recent

Author Topic: MultiThreading  (Read 10881 times)

hac3ru

  • Full Member
  • ***
  • Posts: 113
Re: MultiThreading
« Reply #15 on: August 19, 2013, 10:34:49 am »
Can someone post a code in which the secondary thread signals the main one that he's done working? I can't get an example from the net... :(
Maybe a book to read about SendMessage and PostMessage? Or about LCLMessages?
« Last Edit: August 19, 2013, 02:39:57 pm by hac3ru »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: MultiThreading
« Reply #16 on: August 19, 2013, 06:00:47 pm »
Quote
Can someone post a code in which the secondary thread signals the main one that he's done working? I can't get an example from the net... :(
Maybe a book to read about SendMessage and PostMessage? Or about LCLMessages?
I would just call Synchronize at the end of .Execute

hac3ru

  • Full Member
  • ***
  • Posts: 113
Re: MultiThreading
« Reply #17 on: August 20, 2013, 08:31:54 am »
Well yeah but how will the main thread know that the secondary thread is finished, so it will display the data...?

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: MultiThreading
« Reply #18 on: August 20, 2013, 12:05:16 pm »
Can someone post a code in which the secondary thread signals the main one that he's done working? I can't get an example from the net... :(
Maybe a book to read about SendMessage and PostMessage? Or about LCLMessages?

Here is a good document on multithreading it was written for delphi but it can be used as learning matterial for fpc/lazarus as well.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: MultiThreading
« Reply #19 on: August 20, 2013, 12:06:26 pm »
Thank you very much, taazz

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: MultiThreading
« Reply #20 on: August 20, 2013, 06:22:20 pm »
Quote
Well yeah but how will the main thread know that the secondary thread is finished, so it will display the data...?
Add a field in the secondary thread that states the status of the thread, make the callback passed to synchronize check that field from the main thread.

hac3ru

  • Full Member
  • ***
  • Posts: 113
Re: MultiThreading
« Reply #21 on: August 21, 2013, 09:43:16 am »
Ty for the archive Taazz.
Leledumbo, if I got that right, I'll have another variable that will say if the work is done or not...
If this is the case, it's not good enough... I'll have to check from the main thread for that variable and while it is false, to sleep => can't do anything else.
I want the secondary thread to signal the main one "Hey! I'm done" and the first one to take action on that, right away or after it finishes executing what he is at that moment...

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: MultiThreading
« Reply #22 on: August 21, 2013, 07:23:18 pm »
Quote
If this is the case, it's not good enough... I'll have to check from the main thread for that variable and while it is false, to sleep => can't do anything else.
No, you don't have to do that. Do you know how Synchronize works? Take a good look at "callback" in my previous answer. Get the idea of what "callback" is?

 

TinyPortal © 2005-2018