Florian Klaempfl ha scritto:
Giuliano Colla schrieb:
Isn't that where the dead lock occurs? Suppose Thr1 has just called
Synchronize and is waiting until the main thread has executed the
synchronized method, it won't terminate, because you have suppended
the main thread by waiting for Thr1 to terminate.
I'm afraid you're right.
A really bullet proof way to terminate an application when even a single
thread using synchronize is running is far from straightforward, and
hard to generalize.
For this reason, and many others, I consider the synchronize method just
a hack.
Terminating threads is always not easy and hard to generalize.
You're right, but the available tools can make it easier or harder.
I come from a long experience in real-time applications, with many
concurrent interrelated tasks, and if the design isn't sound enough you
end up with deadlocks at each corner.
What I don't like is a mechanism which may create deadlocks you're
unaware of, because they're dependent on GUI implementation. With a
simple test application I've found different behaviors on Kylix 1, Kylix
3, different versions of Lazarus, and even in the same Lazarus version
with different widgetsets.
I've chosen a different approach. Threads which must use GUI append
messages to a queue, which is processed by the OnIdle event handler.
That way all GUI related code resides in the main thread, and threads
relationships are much simpler to handle.
Of course it works also the other way around. The main thread can append
messages to queues which are processed by threads.
Implementing a thread-safe queue is not so difficult: even a simple ring
buffer can do. BTW are the stack and queue components in the contnrs
unit intended to be thread-safe?
The only thing which currently I miss is a clean way to wake up the main
thread. On Kylix I've found that a Timer event in itself isn't
sufficient: if the event doesn't perform some operation which modify
some widget, then the Application doesn't come out of the idle state,
and therefore the OnIdle event handler isn't activated.
It appears that the IdleTimer of Lazarus behaves much better, but I've
not yet gathered enough data to be sure.
Giuliano
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives