如何识别从msvc中的线程或进程调用的函数

How to identify function called from thread or process in msvc

我有如下程序,函数Foo被线程和主进程调用。现在如何识别函数式Food是线程调用还是主进程调用。

#include <Windows.h>
#include <stdio.h>
DWORD WINAPI Foo(LPVOID lPtr);
int main()
{
    DWORD dwExitCode;
    DWORD dwThreadID;
    HANDLE hT[10];
    int i;
    for( i = 0; i<5; i++)
    hT[i] = CreateThread(
        NULL,
        0,
        Foo,
        0,
        0,
        &dwThreadID
        );
        fflush(stdout); 
    Foo(0);
    return 0;
}

DWORD WINAPI Foo(LPVOID lPtr){
  printf("\ninside the Function");
  return 0;
}

main()中调用GetCurrentThreadId(),在Foo()中再次调用,看两个值是否匹配,例如:

#include <Windows.h>
#include <stdio.h>

DWORD WINAPI Foo(LPVOID lPtr);
DWORD dwMainThreadId;

int main() {
    DWORD dwExitCode;
    DWORD dwThreadID;
    HANDLE hT[10];
    int i;

    dwMainThreadId = GetCurrentThreadId();

    for( i = 0; i<5; i++)
        hT[i] = CreateThread(
            NULL,
            0,
            Foo,
            0,
            0,
            &dwThreadID
        );
    fflush(stdout);
    Foo(0);
    return 0;
}

DWORD WINAPI Foo(LPVOID lPtr){
    DWORD dwThisThreadId = GetCurrentThreadId();
    printf(
        "\ninside the Function in thread %u (%s)",
        dwThisThreadId,
        (dwThisThreadId == dwMainThreadId) ? "main" : "worker"
    );
    return 0;
}