I have created 3 threads in my code:
#include <windows.h>
#include <strsafe.h>
#define MAX_THREADS 3
#define BUF_SIZE 255
typedef struct _MyData {
int val1;
int val2;
} MYDATA, *PMYDATA;
DWORD WINAPI ThreadProc( LPVOID lpParam )
{
HANDLE hStdout;
PMYDATA pData;
TCHAR msgBuf[BUF_SIZE];
size_t cchStringSize;
DWORD dwChars;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
if( hStdout == INVALID_HANDLE_VALUE )
return 1;
pData = (PMYDATA)lpParam;
StringCchPrintf(msgBuf, BUF_SIZE, TEXT("Parameters = %d, %d\n"),
pData->val1, pData->val2);
StringCchLength(msgBuf, BUF_SIZE, &cchStringSize);
WriteConsole(hStdout, msgBuf, cchStringSize, &dwChars, NULL);
HeapFree(GetProcessHeap(), 0, pData);
return 0;
}
void main()
{
PMYDATA pData;
DWORD dwThreadId[MAX_THREADS];
HANDLE hThread[MAX_THREADS];
int i;
for( i=0; i<MAX_THREADS; i++ )
{
pData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(MYDATA));
if( pData == NULL )
ExitProcess(2);
pData->val1 = i;
pData->val2 = i+100;
hThread[i] = CreateThread(
NULL,
0,
ThreadProc,
pData,
0,
&dwThreadId[i]);
if (hThread[i] == NULL)
{
ExitProcess(i);
}
}
WaitForMultipleObjects(MAX_THREADS, hThread, TRUE, INFINITE);
for(i=0; i<MAX_THREADS; i++)
{
CloseHandle(hThread[i]);
}
}
But in tools like performance monitor, process explorer it show only one thread count.
What may be the reason that even after creating 3 threads these tools are showing only one?
Why I am not getting the thread count of 3?