c++ - GetCurrentThreadId returns different threadId -


i call mentioned windows api. returns different thread id id returned _beginthreadex. code following,

threadtest *_threadtest = new threadtest(); thread *_thread = new thread(startroutineforthread,_threadtest); 

constructor thread class is,

threadwin::threadwin(void * (*_startroutine)(void *), void * _argument, bool _isjoinable) {         unsigned int _threadaddress;         unsigned int threadid = _beginthreadex(                                     null,                                     0,                                     (unsigned int (__stdcall *)(void *))_startroutine,                                     _argument,                                     0,                                     &_threadaddress                                 ); } 

startroutineforthread function start routine thread following,

void* startroutineforthread(void* _argument) {     threadtest *_threadtest = (threadtest*)_argument;     _threadtest->run();     return null; } void threadtest::run() {     this->threadid = ::getcurrentthreadid();     } 

now in constructor of class thread value of variable threadid differs value of class threadtest's variablethreadid run function. run function called function specified when have created thread. run function running under same thread have created. why getcurrentthreadid() returns different value returned _beginthreadex ?

well, _beginthreadex doesn't return thread id. thread id stored in _threadaddress, last parameter of _beginthreadex. return value thread handle (like createthread), not id.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -