Thread: thread priority

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    thread priority

    Hello everyone,


    I am confused about the statement from the book Threading in C# about thread priority,

    http://www.albahari.com/threading/

    the confusing statement is, "The ideal solution is to have the real-time work and user interface in separate processes". Why the solution works and ideal?

    The whole paragraph is,

    --------------------
    If the real-time application has a user interface, it can be undesirable to elevate the process priority because screen updates will be given excessive CPU time – slowing the entire computer, particularly if the UI is complex. (Although at the time of writing, the Internet telephony program Skype gets away with doing just this, perhaps because its UI is fairly simple). Lowering the main thread’s priority – in conjunction with raising the process’s priority – ensures the real-time thread doesn’t get preempted by screen redraws, but doesn’t prevent the computer from slowing, because the operating system will still allocate excessive CPU to the process as a whole. The ideal solution is to have the real-time work and user interface in separate processes (with different priorities), communicating via Remoting or shared memory. Shared memory requires P/Invoking
    the Win32 API (web-search CreateFileMapping and MapViewOfFile).
    --------------------


    thanks in advance,
    George

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    it just means that for RT task you want to set process and thread priority to maximum

    if you have a UI thread in the same application - you can lower the thread priority, but process priority will still be high, giving unneded CPU cycles to the UI thread

    So best solution will be extract UI to another process that can have independent process and thread priorities so no additional CPU cycles will be wasted on UI tasks
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks vart,


    You know so many things -- C++ and C#. Question answered. Cool!

    Quote Originally Posted by vart View Post
    it just means that for RT task you want to set process and thread priority to maximum

    if you have a UI thread in the same application - you can lower the thread priority, but process priority will still be high, giving unneded CPU cycles to the UI thread

    So best solution will be extract UI to another process that can have independent process and thread priorities so no additional CPU cycles will be wasted on UI tasks

    regards,
    George

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. crazy pipe/fork
    By fortune2k in forum C Programming
    Replies: 8
    Last Post: 03-13-2009, 11:28 AM
  2. Terminating secondary thread from another thread
    By wssoh85 in forum C++ Programming
    Replies: 13
    Last Post: 12-19-2008, 05:14 AM
  3. Thread Prog in C language (seg fault)
    By kumars in forum C Programming
    Replies: 22
    Last Post: 10-09-2008, 01:17 PM
  4. pointer to main thread from worker thread?
    By draegon in forum C++ Programming
    Replies: 2
    Last Post: 10-27-2005, 06:35 AM
  5. Critical Sections, destroying
    By Hunter2 in forum Windows Programming
    Replies: 4
    Last Post: 09-02-2003, 10:36 PM