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 |
|
|
Library |
|
|
DLL |
|
See also
Send comments about this topic to Microsoft
Build date: 3/7/2012
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.
- 4/15/2011
- ipoverscsi
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.
- 2/22/2010
- darthc