Let's say I have a class with the function

class foo 
{
  ...

  void bar() {
    OutputDebugString(........);
     // mode code
  }
}

Is it possible to print the ID of the current thread (or if it's the main application) that is executing the function using OutputDebugString?

I have a large application I'm debugging and have found a deadlock situation and would like to check which threads are included in the deadlock. Since it could possibly be the same thread that is locking it's own critical section.

有帮助吗?

解决方案

Have a look at the GetCurrentThread function.

其他提示

Use GetCurrentThreadId().

Note that a thread cannot deadlock itself on a critical section. Once a thread has obtained the lock to the critical section, it can freeing re-enter that same lock as much as it wants (same thing with a mutex). Just make sure to unlock the critical section for each successful lock (re)entry so that OTHER threads do not become deadlocked.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top