beginthreadex

How to safely close a THREAD which has a infinite loop in it

懵懂的女人 提交于 2020-08-24 06:28:40
问题 I am creating a thread using _beginthreadex function. The function address I am passing in it has an infinite while loop ( while(1) ) . I have the threadid and threadhandle . I can use TerminateThread(threadhandle,1); But it is dangerous. The safe way is to kill thread using _endthreadex but it can only be used from inside the thread, and I wanted to kill the thread from outside. So please suggest if there is a safe way to close,end or kill the thread safely from outside using threadid or

How to safely close a THREAD which has a infinite loop in it

旧巷老猫 提交于 2020-08-24 06:28:11
问题 I am creating a thread using _beginthreadex function. The function address I am passing in it has an infinite while loop ( while(1) ) . I have the threadid and threadhandle . I can use TerminateThread(threadhandle,1); But it is dangerous. The safe way is to kill thread using _endthreadex but it can only be used from inside the thread, and I wanted to kill the thread from outside. So please suggest if there is a safe way to close,end or kill the thread safely from outside using threadid or

_beginthreadex cannot convert from 'overloaded-function'

雨燕双飞 提交于 2019-12-09 03:52:55
问题 So I was making a function to print text layered across a different window, and I wanted it to be in a separate thread so I can run a timer for the text to display while leaving the user open to continue using the program. However, when I compile I get this error: error C2664: '_beginthreadex' : cannot convert parameter 3 from 'overloaded-function' to 'unsigned int (__stdcall *)(void *)' Here's the main cpp file: #include "stdafx.h" #include "Trial.h" int main() { wchar_t* text = L"Message!";

Can I call CloseHandle() immediately after _beginthreadex() succeeded?

痞子三分冷 提交于 2019-12-07 02:05:51
问题 I'm not interested in using the handle returned from _beginthreadex() . Is it safe to call CloseHandle() on it immediately? I believe this must be done to avoid memory leaks. 回答1: Yes, you can close the handle as soon as you decide you no longer need that handle. That won't affect thread execution. However you likely should check whether the thread has been started at all before you proceed. The leaks you're concerned about are not memory leaks, they are system resources leaks - usually they

Can I call CloseHandle() immediately after _beginthreadex() succeeded?

♀尐吖头ヾ 提交于 2019-12-05 05:42:39
I'm not interested in using the handle returned from _beginthreadex() . Is it safe to call CloseHandle() on it immediately? I believe this must be done to avoid memory leaks. Yes, you can close the handle as soon as you decide you no longer need that handle. That won't affect thread execution. However you likely should check whether the thread has been started at all before you proceed. The leaks you're concerned about are not memory leaks, they are system resources leaks - usually they are much worse. According to MSDN, you should not close the handle returned by __beginThreadEx: _endthread