Thread paused
-
I have a thread, it is has a normal priority, when it starts to excute, it runs for 5 or 6 seconds then stops for 3 or 4 seconds and run again, stops again this goes till it finishes his work. Any idea why this happens, programm code is in Visual C++. Thanks
-
I have a thread, it is has a normal priority, when it starts to excute, it runs for 5 or 6 seconds then stops for 3 or 4 seconds and run again, stops again this goes till it finishes his work. Any idea why this happens, programm code is in Visual C++. Thanks
Isn't that (being scheduled) the normal thread beahviour? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
I have a thread, it is has a normal priority, when it starts to excute, it runs for 5 or 6 seconds then stops for 3 or 4 seconds and run again, stops again this goes till it finishes his work. Any idea why this happens, programm code is in Visual C++. Thanks
I prefer you to read chapter 2. Processes and threads from "Modern Operating Systems" by Andrew S Tannenbaum. It will be useful for you.
Величие не Бога может быть недооценена.
-
Isn't that (being scheduled) the normal thread beahviour? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Simply don't do that. It is normal for threads being scheduled. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Isn't that (being scheduled) the normal thread beahviour? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
I have a thread, it is has a normal priority, when it starts to excute, it runs for 5 or 6 seconds then stops for 3 or 4 seconds and run again, stops again this goes till it finishes his work. Any idea why this happens, programm code is in Visual C++. Thanks
-
Can you please post your threads code to see if they are waiting for some reason. Edit: Did some typo.
Greetings Covean
void CMyThread::ThreadStart() { if (m_pSelThread != NULL) // CWinThread* m_pSelThread; { if (::WaitForSingleObject(m_pSelThread->m_hThread, 0) != WAIT_OBJECT_0) return; delete m_pSelThread; m_pSelThread = NULL; } m_pSelThread = AfxBeginThread((AFX_THREADPROC)ThreadFunction, this, THREAD_PRIORITY_NORMAL, 0,CREATE_SUSPENDED); m_pSelThread->m_bAutoDelete = FALSE; m_pSelThread->ResumeThread(); } UINT CMyThread::ThreadFunction ( LPVOID param ) { while(!bTerminate) // bool bTerminate { if ((::WaitForSingleObject(m_Sel_End_Event, 0) == WAIT_OBJECT_0)) { bTerminate = true; continue; } }
-
Being scheduled is normal thread behaviour! But it's not a normal thread behaviour to wait 3-5 seconds to get the next time slice!
Greetings Covean
True but it really depends on how those 3-5 seconds come out? Are they just a OP impression? How did she measure them? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
void CMyThread::ThreadStart() { if (m_pSelThread != NULL) // CWinThread* m_pSelThread; { if (::WaitForSingleObject(m_pSelThread->m_hThread, 0) != WAIT_OBJECT_0) return; delete m_pSelThread; m_pSelThread = NULL; } m_pSelThread = AfxBeginThread((AFX_THREADPROC)ThreadFunction, this, THREAD_PRIORITY_NORMAL, 0,CREATE_SUSPENDED); m_pSelThread->m_bAutoDelete = FALSE; m_pSelThread->ResumeThread(); } UINT CMyThread::ThreadFunction ( LPVOID param ) { while(!bTerminate) // bool bTerminate { if ((::WaitForSingleObject(m_Sel_End_Event, 0) == WAIT_OBJECT_0)) { bTerminate = true; continue; } }
I couldn't find any reason why your thread pauses for 3-5 seconds. But your "main loop" is a kind of resource-eating. Do you really meant to use a timeout of 0 to wait for this object? 0 timeout means to check the signaled state of the waitable handle and to return immediately. So your loop will iterate very very fast and consumes nearly 100% processing time.
UINT CMyThread::ThreadFunction(LPVOID param)
{
while(!bTerminate) // bool bTerminate
{
if ((::WaitForSingleObject(m_Sel_End_Event, 0) == WAIT_OBJECT_0))
{
bTerminate = true;
continue;
}
}
}But as I said before this doesn't solve your problem. Is there maybe more code you can provide? By the way you also use the 0 timeout also in your ThreadStart function (but there it shouldn't be a problem).
Greetings Covean
-
True but it really depends on how those 3-5 seconds come out? Are they just a OP impression? How did she measure them? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]Yes there you are right. But in normal nobody should notice the thread-switches (if the thread and the process doesn't have the lowest priority or many real-time priority processes are running), so I would assume that the op has a real problem with it, no matter if the thread pauses for 300-500ms or 3-5s.
Greetings Covean
-
Isn't that (being scheduled) the normal thread beahviour? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Uh?! OP missed? :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]