Note that there are some explanatory texts on larger screens.

plurals
  1. POBackground threads when using pthreads (nice, priority)
    primarykey
    data
    text
    <p>I have a GUI application that's using pthreads to do some heavy background processing.</p> <p>While the background processing is running the GUI is very unresponsive and I think that this is because it's being starved of CPU time by the background threads.</p> <p>On Windows you can ::SetThreadPriority(hThread, THREAD_PRIORITY_BELOW_NORMAL) on the background threads and all is well.</p> <p>However on Linux I'm using pthreads and I cannot find a good alternative. </p> <p>I've already considered;</p> <ul> <li>::sched_setscheduler(SCHED_FIFO) or ::sched_setscheduler(SCHED_RR) - this isn't viable as it requires root (not nice for my GUI app) - also this will make the GUI thread have way too much CPU; I only want the GUI to be prioritised over the background threads.</li> <li>::pthread_setschedparam but when using anything other than SCHED_FIFO or SCHED_RR that's not supported (::sched_get_priority_min(SCHED_OTHER) and ::sched_get_priority_max(SCHED_OTHER) both return 0)</li> <li>Have multiple processes and use ::nice. There is too much coupling between the GUI and the background threads to make this viable (and porting so much code to this design is a major amount of work)</li> <li>Use ::setpriority to re-nice the background threads. This does work - but is directly against what the documentation says: <a href="http://www.kernel.org/doc/man-pages/online/pages/man7/pthreads.7.html" rel="nofollow">PThreads documentation</a> (so could potentially be "fixed" system-wide at a later date)</li> </ul> <p>I'm convinced that this is quite a common pattern for GUI apps so what have I missed?</p> <p>Marcus.</p> <p>EDIT: Added ::setpriority to list of options (thanks ZalewaPL)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload