How to find out which thread is currently running

Started by
2 comments, last by Floating 18 years ago
Hi, How can I find out about which thread I am currently in? I start my threads like: AfxBeginThread(thread1,NULL,THREAD_PRIORITY_NORMAL); AfxBeginThread(thread2,NULL,THREAD_PRIORITY_NORMAL); Is there some global variable that I could maybe check? Or some function that I can call? Thanks
Advertisement
If the code from the thread1 function is being run then you're in that first thread. If the code from the thread2 function is being run then you're in the second thread. That's really all you have to go by - if you're not in that function then you're not in that thread.
GetCurrentThreadId
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Quote:Original post by Colin Jeanne
If the code from the thread1 function is being run then you're in that first thread. If the code from the thread2 function is being run then you're in the second thread. That's really all you have to go by - if you're not in that function then you're not in that thread.


Yes, but what if both threads call a common function?? Then from within that function I can't know which thread called it!

Thanks LessBread, that's what I was looking for :)

This topic is closed to new replies.

Advertisement