[Lazarus] PostMessage return value
Michael Schnell
mschnell at lumino.de
Mon Sep 15 16:30:49 CEST 2014
On 09/15/2014 03:57 PM, Xiangrong Fang wrote:
> 2014-09-15 21:44 GMT+08:00 Michael Schnell <mschnell at lumino.de
> <mailto:mschnell at lumino.de>>:
>
>
> Performance wise it's better not to destroy and create your
> threads but to manage a thread pool and assign work to the threads
> as appropriate.
>
> Here you would have the threads wait for work e.g. by trapping
> themselves in a TCriticalSection for each one.
>
> Now the Main thread can easily free a thread after it assigned
> work to it (e.g. by providing a callback function that is to be
> called in TThread.Execute). If work is done, the Thread could
> notify the manager (in the main thread) by
> Application.QueueAsyncCall or TThread.Queue. TThread. Synchronize
> would not harm in this case either, as the thread at that time has
> nothing to do anyway.
>
>
> That's exactly what I planed to do. But I don't know
> "CriticalSections" can be used in here.
Why not (of course there might be alternatives).
> My original thinking is that, by the end of Execute, I call either
> PostMessage or QueueAsyncCall to notify main thread that the current
> thread finished its work.
OK. Moreover TThread.Queue and TThread.Synchronize will work.
> The main thread, in its message handler
(This is the procedure given in Application.QueueAsyncCall,
TThread.Queue and TThread.Synchronize)
> then know from a status variable that this thread is in suspended status,
OK, suspend will work similar to TCrtiticalSection. But for me Suspend
is a bit suspicious, as there is no direct Linux and Information-Science
equivalent to same (while TCriticalSection directly maps to a Semaphore).
> then assign a new work to it and call its Execute() method again.
I don't know how to " call its Execute()". I feel that you can't leave
the Execute procedures without killing the thread. So you need to call
the work-procedure from the execute procedure.
>
> Is that ok? To be exact, when a thread's execute() finished, it will
> go to a "sleep" status,
No. It will die.
> and can be reused by calling execute() again, right?
AFAIK: No.
-Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140915/12fd7566/attachment-0003.html>
More information about the Lazarus
mailing list