locked
Setting a threads priority by its ID...

    Question

  • Hi guys,

    Is there a way to set the threads priority (eg. for a thread started via std::thread) by its id ?
    Currently it seems the only way to achieve this with WinRT is using Windows::System::Threading::ThreadPool::RunAsync
    which i  would rather like to avoid.

    Any hunches anybody please ?

    Thanks,
    Roman

    Roman Pfneudl CEO - vertex4 entertainment ltd.

    Friday, June 1, 2012 9:27 AM

Answers

  • Hi Roman,

    Thanks for your reply!  The ThreadPool work item priority can only be set in the RunAsync() at task creation time.  The Low, Normal, High priorities don't give you the same level of granularity as the Win32 thread priorities, so this isn't the best way to control background audio playback.  A better way would be to use XAudio2 (http://msdn.microsoft.com/en-us/library/windows/apps/hh452794.aspx) because this is optimized for both long-term background audio like music, plus short-term game sounds.  XAudio2 handles all the thread priority stuff internally and should give you the smooth playback you're looking for.  A friend of mine used it for his game and he said it worked out really well.

    I don't have a lot of experience with XAudio2, but if you have questions about it, please the Building Metro style games with DirectX forum and the folks there can give you additional help.

    Sincerely,

    Dan Ruder [MSFT]

    Wednesday, June 13, 2012 8:20 PM
    Moderator

All replies

  • Yes, it is union solution.

    NEU_ShieldEdge

    Monday, June 4, 2012 7:06 AM
  • What exactly does this mean ?  :)

    Roman Pfneudl CEO - vertex4 entertainment ltd.

    Monday, June 11, 2012 4:49 PM
  • Hi Roman,

    The Win32 thread APIs like CreateThread and SetThreadPriority are not supported in Metro style apps.  The two choices for threading functions are the Windows.System.Threading.ThreadPool class or the PPL.

    ThreadPool:  http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.threading.aspx

    PPL:  http://msdn.microsoft.com/en-us/library/dd492418(v=vs.110)

    Creating Async Operations in C++ for Metro style apps (http://msdn.microsoft.com/en-us/library/hh750082(v=vs.110)#exethread

    What are you trying to accomplish and why do youi wish to advoid the ThreadPool class?

    Thanks,

    Dan Ruder [MSFT]


    Tuesday, June 12, 2012 12:25 AM
    Moderator
  • Hi Dan,

    thanx for your answer.

    Well, i start a thread for my sound-streaming very early in the game, so the user already hears the tune while a lot of other stuff is loaded into memory. The threads code is very simple:

    while (!bRequestShutdown)
    {
      updateStreamingVoices (); // filling buffer parts if necessary.
      sleep (250);
    }

    Under win32 i gave this thread HIGHPRIORITY or even TIMECRITICAL - otherwise the sound would hickup during startup. The same occurs now in windows 8. The PPL-link is broken btw.

    I just try to avoid it to keep my code as simple and readable as possible. I abstract every system-call in my framework, and
    thus try to use platform independent methods whereever i can. So until now i had a ulong pf::thread_create (...) returning a thread id,
    and a pf::thread_setHighPriority (ulong ulThreadId) which i used. Now it seems i have to extend/change that which is ok, I just need to know.

    So, my question now is:
    Is it possible to set a tasks priority after its creation OR is it only possible to define it via the RunAsync at task creation time ?

    Kind regs,



    Roman Pfneudl CEO - vertex4 entertainment ltd.



    • Edited by v4corg Tuesday, June 12, 2012 10:14 AM
    Tuesday, June 12, 2012 9:58 AM
  • Hi Roman,

    Thanks for your reply!  The ThreadPool work item priority can only be set in the RunAsync() at task creation time.  The Low, Normal, High priorities don't give you the same level of granularity as the Win32 thread priorities, so this isn't the best way to control background audio playback.  A better way would be to use XAudio2 (http://msdn.microsoft.com/en-us/library/windows/apps/hh452794.aspx) because this is optimized for both long-term background audio like music, plus short-term game sounds.  XAudio2 handles all the thread priority stuff internally and should give you the smooth playback you're looking for.  A friend of mine used it for his game and he said it worked out really well.

    I don't have a lot of experience with XAudio2, but if you have questions about it, please the Building Metro style games with DirectX forum and the folks there can give you additional help.

    Sincerely,

    Dan Ruder [MSFT]

    Wednesday, June 13, 2012 8:20 PM
    Moderator
  • Hi Dan,

    Ah ok, thank you. Well then I'll have to settle for the workitem-RunAsync approach.
    Thank you.

    Kind regs,
    Roman


    Roman Pfneudl CEO - vertex4 entertainment ltd.

    Wednesday, June 13, 2012 10:54 PM