c# - 监控线程创建

标签 c# c++ visual-studio-2010 visual-studio visual-c++

我一直在为从 Windows XP 开始的 Windows 版本开发驱动程序。为此,我使用例程 PsSetCreateThreadNotifyRoutine。在注册的回调中,我试图访问线程的上下文,但我没有得到。查到信息说当回调函数被调用时,线程还不在将要使用的上下文中。

我想知道是否有像 kewaitforsingleobject 这样的函数会在这些线程获得上下文时发出信号?

我尝试为出现的每个线程创建一个新线程并让它们等待,但我认为这不是最佳解决方案。

在这种情况下,等待线程接收其上下文的最佳方式是什么?

最佳答案

由于MSDN :

The driver's thread-notify routine runs at IRQL = PASSIVE_LEVEL. When a thread is created, the thread-notify routine runs in the context of the thread that created the new thread. When a thread is deleted, the thread-notify routine runs in the context of this thread when the thread exits.

因此在创建新线程时您可以访问父线程的上下文。 我不确定,但似乎您也可以在删除时访问删除线程的上下文。 (或者可能又是 parent )

因此,您可以使用一个列表来存储线程 ID,并让工作线程检查每个 TID。 不要忘记互斥。您可以使用 MUTEX 或 SPINLOCK(不知道它们在 WDK 中的实际名称)。

关于c# - 监控线程创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19470548/

相关文章:

c# - 如何在 linq to sql 中编写不等于运算符?

c# - 有什么方法可以使声音静音但又可以使其在后台运行而不是完全停止播放?

c# - MySql和 Entity Framework 导致 "Object reference not set to an instance of an object."

c++ - < : syntax in C? 的意义是什么

c++ - 循环迭代器时抛出 "Debug assertion failed"错误

c# - 在 PHP 中将 int 转换为 char 在 C# 中有不同的输出

c++ - 将按钮界面添加到我的控制台应用程序

android - Visual Studio 2010 看不到 Nexus 4

c++ - 为什么 C++ 仍在使用 stdio.h?

c++ - 为什么使用 gcc 和模板函数使用两个或更多基于 typedef 的静态断言时会出现 "conflicting declaration"错误?