title: Change boost thread priority in Windows
body: <p>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?</p>
  
  <p>Any one know how to do this?</p>
  
  <pre><code>void baseThread::applyPriority(uint8 priority)
  {
  
  #ifdef WIN32
      if (!m_pThread)
          return;
  
      BOOL res;
      HANDLE th = m_pThread-&gt;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
  }
  </code></pre>
  
  <p>edit: Final code:</p>
  
  <pre><code>void baseThread::applyPriority(uint8 priority)
  {
  
  #ifdef WIN32
      if (!m_pThread)
          return;
  
      BOOL res;
      HANDLE th = m_pThread-&gt;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
  }
  </code></pre>