简体   繁体   中英

Get ID of executing Process/Thread in C++ Builder

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.

看一下GetCurrentThread函数。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM