KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Im trying to change the thread priority in boost but im having no luck. Im getting a bad handle error (type 6) from the GetLastError function. I though native_handle() returned the handle for the thread? Any one know how to do this? void baseThread::applyPriority(uint8 priority) { #ifdef WIN32 if (!m_pThread) return; BOOL res; HANDLE th = m_pThread->native_handle(); switch (priority) { case REALTIME : res = SetPriorityClass(th, REALTIME_PRIORITY_CLASS); break; case HIGH : res = SetPriorityClass(th, HIGH_PRIORITY_CLASS); break; case ABOVE_NORMAL : res = SetPriorityClass(th, ABOVE_NORMAL_PRIORITY_CLASS); break; case NORMAL : res = SetPriorityClass(th, NORMAL_PRIORITY_CLASS); break; case BELOW_NORMAL : res = SetPriorityClass(th, BELOW_NORMAL_PRIORITY_CLASS); break; case IDLE : res = SetPriorityClass(th, IDLE_PRIORITY_CLASS); break; } if (res == FALSE) { int err = GetLastError(); } #endif } edit: Final code: void baseThread::applyPriority(uint8 priority) { #ifdef WIN32 if (!m_pThread) return; BOOL res; HANDLE th = m_pThread->native_handle(); switch (priority) { case REALTIME : res = SetThreadPriority(th, THREAD_PRIORITY_TIME_CRITICAL); break; case HIGH : res = SetThreadPriority(th, THREAD_PRIORITY_HIGHEST); break; case ABOVE_NORMAL : res = SetThreadPriority(th, THREAD_PRIORITY_ABOVE_NORMAL); break; case NORMAL : res = SetThreadPriority(th, THREAD_PRIORITY_NORMAL); break; case BELOW_NORMAL : res = SetThreadPriority(th, THREAD_PRIORITY_BELOW_NORMAL); break; case IDLE : res = SetThreadPriority(th, THREAD_PRIORITY_LOWEST); break; } #endif }
Tags (comma-separated)
Save Edits
Cancel