Archived

This topic is now archived and is closed to further replies.

Truckhunter

Thread angst in Windows

Recommended Posts

I''m working on an interesting project right now that involves some multi-threaded stuff for game development. However, I''m running into some blocks with the win32 API. I''m using the standard API with CreateThread/SuspendThread/ResumeThread/... for my thread manager. What I want to be able to do is, given a thread handle or thread id, find out if that current thread is blocked (specifically, waiting on a semaphore.) Does anyone know how to do this with the Windows Thread API? Or are there any other thread API''s that can be used under Windows that might allow this kind of functionality?

Share this post


Link to post
Share on other sites
Ick, what are you really trying to do that you need this level of info? I don''t think there is a standard way to determine if a thread is blocked. You might be able to play games with GetThreadContext but there won''t be any guarantees.

I believe that SuspendThread is really only meant to be used by debuggers - at least I''ve never needed it.

-Mike

Share this post


Link to post
Share on other sites
If you need to know that, threading hasn''t made your life any easier :p

To detect a stalled thread you can use global watch-dog counters. Each thread gets a global hole that it increments while it''s running (in lingo "kicks the dog"). Then you decide on a time-out, and if the watch-dog doesn''t twiddling in that time-out perdio you assume it has stalled.

Share this post


Link to post
Share on other sites
I guess I''ll clarify why I need this information a bit more. What I''m working on is a research project to see what possible benefits could be found by applying a few different Real-time scheduling algorithms to interactive multimedia applications (games being one, but not the only, example of this.) So what I need to write is my own thread manager that will be responsible for managing the threads belonging to the tasks that it is given. Because I''m working on a reusable API, I won''t know for sure what kind of synchronization methods the application will use, so I can''t rely on any of that information. I may be able to adapt the watchdog approach, but I''m not sure if it would be the most efficient. If I can''t get that to work, I''ll post something new with more details about the specific situation

Thanks

Share this post


Link to post
Share on other sites