4 out of 17 rated this helpful - Rate this topic

GetCurrentThreadId function

Applies to: desktop apps | Metro style apps

Retrieves the thread identifier of the calling thread.

Syntax

DWORD WINAPI GetCurrentThreadId(void);

Parameters

This function has no parameters.

Return value

The return value is the thread identifier of the calling thread.

Remarks

Until the thread terminates, the thread identifier uniquely identifies the thread throughout the system.

Examples

For an example, see Using Thread Local Storage.

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Header

WinBase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

GetCurrentThread
OpenThread
Process and Thread Functions
Threads

 

 

Send comments about this topic to Microsoft

Build date: 3/7/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Valid Thread IDs
From what I can tell using Process Explorer, a thread with an ID of zero does exist, but it is used by the operating system to accumulate idle time.  I suspect that you can use an ID of zero as a sentinel value to indicate that no thread currently holds an object or a lock.
What is a valid thread id?
I have a variable that indicates which thread owns an object. But how can I inform that the object has no owner? Should I use zero? INVALID_HANDLE_VALUE? 0xFFFFFFFF?

As of this writing, this topic tells nothing about which are valid thread ids. I'm using zero and it seems to work (GetCurrentThreadId never returned zero to me), but I think this should be clearly specified.