Delphi threads deadlock

Posted by Lobuno on Stack Overflow See other posts from Stack Overflow or by Lobuno
Published on 2010-03-25T11:35:23Z Indexed on 2010/03/25 12:03 UTC
Read the original article Hit count: 485

Filed under:
|

Hello!

I am having a problem sometimes with a deadlock when destroying some threads. I've tried to debug the problem but the deadlock never seems to exist when debugging in the IDE, perhaps because of the low speed of the events in the ide.

The problem:

  • The main thread creates several threads when the application starts. The threads are always alive and synchronizing with the main thread. No problems at all. The threads are destroyed when the applcation ends (mainform.onclose) like this:

thread1.terminate; thread1.waitfor; thread1.free; and so on.

but some times one of the threads (which logs some string to a memo, using synchronize) will lock the whole application when closing. I suspect that the thread is synchronizing when I call waitform and the harmaggeddon happens, but that's is just a guess because the deadlock never happens when debbuging (or I've never been able to reproduce it anyway). Any advice?

© Stack Overflow or respective owner

Related posts about delphi

Related posts about threads