Question

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.

Était-ce utile?

La solution

Have a look at the GetCurrentThread function.

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top