Glenn1234
Glenn1234

Reputation: 2582

Why does my program hang when I call Free on a thread?

I dropped using FreeOnTerminate := true in favor of setting it explicitly to false, but now the code locks up every time I attempt to explicitly free the thread. I determined the lockup occurs at the Free statement.

For the last step of the thread process, I'm sending a message to a window handle I created in the main object to signal "finish." There I'm running a event, and then doing the free. Why does this happen?

Upvotes: 3

Views: 220

Answers (1)

Justmade
Justmade

Reputation: 1496

I think that this is a typical multi-threading dead-lock.

When your thread sends the finish signal through sendmessage, the thread waits for the sendmessage to return before it will do anything else (e.g. the free procedure). At the same time, your main thread is waiting for the thread to free before finishing the event and processing the thread's sendmessage.

Have you tried to use postmessage instead which returns immediately and does not wait for result?

Upvotes: 6

Related Questions