确定一个dll是否被应用程序中的多个线程调用-使用ThreadId

Determine if a dll is being called by multiple threads from an application - Use ThreadId?

本文关键字:线程 调用 使用 应用程序 ThreadId 一个 是否 dll      更新时间:2023-10-16

我创建了一个静态dll文件,供某个应用程序使用。我想知道该dll的导出方法是由该应用程序的单独线程还是由单个线程调用的。我在想,如果我输出调用dll中方法的线程的线程,这可能有助于我弄清楚该函数是由单个线程还是多个线程调用的。这有帮助吗?另外,我将如何得到线程的线程,正在调用dll ?

使用GetCurrentThreadId函数

std::vector<DWORD> ids;
__declspec(dllexport) int __stdcall SomeFunction()
{
    DWORD id = GetCurrentThreadID();
    if (std::find(ids.begin(), ids.end(), id) != ids.end())
    {
        // New thread uses this function
        ids.push_back(id);
    }
}