Why is the thread status dead?

1.1k Views Asked by At

That is the question. I called a function using a thread, but when I return to main control, main becomes in sleep status within a few moments.

Example (Look here is a line that calls a Win32API function GetMessage):

Start()
e = Thread.new { Look() }
for _i in 0..1000
    puts e.status
end

This code should print the e's status 1000 times, but it just prints once. I cannot find a reasonable error. Look does not return until it gets a message, so I suspect that this could be causing an error.

2

There are 2 best solutions below

6
On

My guess is that the status of e is nil, which puts displays as an empty string.

A nil status means the thread terminated abnormally.

Whatever is wrong, your code is printing something 1000 times, and you should put some visible text in the puts to show that.

Also, rather than use a throw-away variable _i, write

1000.times do
    puts e.status
end
0
On

I solved thanks for all your help, the error was in that i only need to change GetMessageA for PeekMessage so thread doesn't interpret that is dead jeje

Some.Proxy