On 01/07/2014 06:11 PM, Mark Morgan Lloyd wrote:
IMHO, the Pascal way of handling such task is using a thread.
That's in the main code, not a background thread, and I have good
reasons for wanting to do it like that.
OK. There are decent reasons in certain projects. But Generally the
"Pascal way" is to do event driven programming. If you do a blocking I/O
in the main thread, the project is completely idle until the I/O device
unblocks it. This is not desirable as soon as anything should be done in
the meantime. That is why it usually is the better way to do blocking
I/O only in a thread. But if you do that, you mostly need a mechanism to
notify the main thread about the proceedings in all threads. This is
only decently handled by an event queue such as provided by
TThread.Synchronize, TThread.Queue, CheckSynchronize, WakeMainThread, ...
The question was whether I could still use TThread.Synchronize for
background threads, which do not in this particular case need a
significant amount of OS interaction.
It does not make much sense to use TThread.Synchronize if the main
thread can block in any other place than in CheckSynchronize.
-Michael
--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus