Behaviour of CreateThread compared to AfxBeginThread
-
Hi all, Im working in vc6.0 using MFC. When I create thread using AfxBeginThread(), if the thread is running then the CPU utilization shown is around 50%, even though the thread is doing nothing. It is called as: AfxBeginThread(PortReadThread,gpSerialPortCtrl,THREAD_PRIORITY_NORMAL); If I create the same thread using CreateThread(),even the thread is running the CPU utilization is around 0% It is called as: CreateThread( NULL,0,(LPTHREAD_START_ROUTINE) PortReadThread,(LPVOID) this,0,NULL); Is this the expected behaviour.If not please tell me why its behaving like that. Thanks in advance.
Regards, Sunil Kumar
-
Hi all, Im working in vc6.0 using MFC. When I create thread using AfxBeginThread(), if the thread is running then the CPU utilization shown is around 50%, even though the thread is doing nothing. It is called as: AfxBeginThread(PortReadThread,gpSerialPortCtrl,THREAD_PRIORITY_NORMAL); If I create the same thread using CreateThread(),even the thread is running the CPU utilization is around 0% It is called as: CreateThread( NULL,0,(LPTHREAD_START_ROUTINE) PortReadThread,(LPVOID) this,0,NULL); Is this the expected behaviour.If not please tell me why its behaving like that. Thanks in advance.
Regards, Sunil Kumar
Actually the AfxBeginThread() also calls the CreateThread() function internally to create a thread. so basically there should not be any difference in CPU utitlization. Some additional tasks AfxBeginThread() perform is the initialization of MFC and CRT global variables and thread specific variables. Also try the _beginthread().
sunilkumar.d wrote:
even though the thread is doing nothing.
Nothing means? is it in some wait state?
-
Actually the AfxBeginThread() also calls the CreateThread() function internally to create a thread. so basically there should not be any difference in CPU utitlization. Some additional tasks AfxBeginThread() perform is the initialization of MFC and CRT global variables and thread specific variables. Also try the _beginthread().
sunilkumar.d wrote:
even though the thread is doing nothing.
Nothing means? is it in some wait state?
-
Not in wait state exactly.just to test the application i have put a while loop with empty braces in the thread.
Regards, Sunil Kumar
Well thread is not doing nothing. The thread is busy executing infinite loop!!! -Saurabh
-
Not in wait state exactly.just to test the application i have put a while loop with empty braces in the thread.
Regards, Sunil Kumar
sunilkumar.d wrote:
Not in wait state exactly.just to test the application i have put a while loop
Ho :doh: . Then the thread will definitly use cpu and the AfBeginThread() is working properly. I guess there is something wrong in calling Createthread() not in AfBeginThread(). :cool:
-
Actually the AfxBeginThread() also calls the CreateThread() function internally to create a thread. so basically there should not be any difference in CPU utitlization. Some additional tasks AfxBeginThread() perform is the initialization of MFC and CRT global variables and thread specific variables. Also try the _beginthread().
sunilkumar.d wrote:
even though the thread is doing nothing.
Nothing means? is it in some wait state?
Naveen wrote:
Actually the AfxBeginThread() also calls the CreateThread() function internally to create a thread.
Nope, that's wrong. AfxBeginThread calls _beginthreadex internally.
There are some really weird people on this planet - MIM.