I'm trying to port some code to 64-bit, but it seems that the thread
address
identifier in _beginthreadex
is unsigned int
which is 32-bits and I can't pass/receive a 64-bit
address
identifier from the function:
uintptr_t _beginthreadex( // NATIVE CODE
void *security,
unsigned stack_size,
unsigned ( __stdcall *start_address )( void * ),
void *arglist,
unsigned initflag,
unsigned *thrdaddr // <-- 32-bit address
);
I checked the MSDN documentation , but I didn't see a 64-bit version of the function. Am I including the wrong header, per-processor flag or is there some other way to create a thread with a 64-bit
address
identifier?
The documentation states that the thrdaddr
parameter is 32-bit:
Thrdaddr
Points to a 32-bit variable that receives the thread identifier. Might be NULL, in which case it is not used.
The thrdaddr
parameter receives the thread ID. It is not the address of the thread function. It appears to be an exceedingly badly named parameter.
The start_address
parameter is the thread function pointer and you can pass your 64 bit function pointer in that parameter.
Your update to the question suggests that you believe that the thread ID is a 64 bit value on 64 bit Windows. That is a mis-think. Thread IDs are 32 bit values on all flavours of Windows.
From the documentation :
Thrdaddr
Points to a 32-bit variable that receives the thread identifier. Might be NULL, in which case it is not used.
In other words, thrdaddr
gets the thread id. It is not an address for the thread.
In 64-bit, all pointers are 64-bits. So this just works.
You're getting some of the arguments mixed up. The address for your thread proc will be passed in as start_address
. thrdaddr
is an optional parameter than receives the thread ID.
HANDLE hThread;
unsigned threadID;
hThread = (HANDLE)_beginthreadex(
NULL,
0,
&YourThreadProc, // this is your thread procedure
NULL,
0,
&threadID); // threadID will hold the ID of the new thread
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.