Thread Count in C++

If you want to get the thread count of your process, following code may help:

 DWORD pid = ::GetCurrentProcessId ();
 THREADENTRY32 entry;
 entry.dwSize = sizeof (THREADENTRY32 );
 int count;
 HANDLE handle = ::CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD , pid );
 BOOL enum_more = Thread32First ( handle, & entry);
 count = 0;
 while (1)
 {
   enum_more = Thread32Next ( handle, & entry);
   if ( !enum_more )
     break;
   if ( entry.th32OwnerProcessID == pid )
    count ++;
 }
 

After this code the *count* variable contains the thread count.

Advertisements

One Response to “Thread Count in C++”

  1. omerash Says:

    if ( entry.th32OwnerProcessID == pid )

    bhai yeah line kia kertee hia ??

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: