nice for pthreads? (Linux)

This is a discussion on nice for pthreads? (Linux) within the C Programming forums, part of the General Programming Boards category; With Linux kernel 2.6 nice() called inside a pthread affects only the calling thread or all threads of the process?? ...

  1. #1
    Alessio Stella
    Join Date
    May 2008
    Location
    Italy, Bologna
    Posts
    251

    nice for pthreads? (Linux)

    With Linux kernel 2.6
    nice() called inside a pthread
    affects only the calling thread
    or all threads of the process??
    (I guess in POSIX it affects the process, but Linux is not fully POSIX compliant cause threads are actually processes for the kernel scheduler)

    In case it affects all process's threads, is there a call something like pthread_nice() to affect one thread only?
    Please do not answer set_sched_param() cause that will not work for SCHED_OTHER policy as stated here

    "pthread_setschedparam sets the scheduling parameters for the thread target_thread as indicated by policy and param. policy can be either SCHED_OTHER (regular, non-realtime scheduling), SCHED_RR (realtime, round-robin) or SCHED_FIFO (realtime, first-in first-out). param specifies the scheduling priority for the two realtime policies. See sched_setpolicy(2) for more information on scheduling policies. "
    at http://www.linuxmanpages.com/man3/pt...param.3thr.php

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,249
    The verbiage is unclear, but a man page isn't an official document anyway. Some Googling reveals lots of examples on the web of using pthread_setschedparam() to set the priority of a SCHED_OTHER thread -- either these examples are all wrong, or it works.

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,676
    Ideally, your MT design wouldn't rely on on the scheduling algorithm, for efficiency or correctness.

    Why do you feel the need to call something like "pthread_nice()"?

    gg

  4. #4
    Alessio Stella
    Join Date
    May 2008
    Location
    Italy, Bologna
    Posts
    251
    Quote Originally Posted by brewbuck View Post
    The verbiage is unclear, but a man page isn't an official document anyway. Some Googling reveals lots of examples on the web of using pthread_setschedparam() to set the priority of a SCHED_OTHER thread -- either these examples are all wrong, or it works.
    this is very curious and interesting
    if you still have some links please give them!!

  5. #5
    Alessio Stella
    Join Date
    May 2008
    Location
    Italy, Bologna
    Posts
    251
    Quote Originally Posted by Codeplug View Post
    Ideally, your MT design wouldn't rely on on the scheduling algorithm, for efficiency or correctness.

    Why do you feel the need to call something like "pthread_nice()"?

    gg
    I agree with you. Relying on nice is not the case, also because nice lvel is +-5 changed by the sched. But I think it helps effciency.

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,676
    >> I think it helps effciency
    Keep in mind that doing something faster doesn't make it more efficient

    I look at it as "Taking cpu time away from other tasks". There's not a whole lot of good reasons for doing this.

    If you can make the code "correct" regardless of scheduling, then I would do that first. In the meantime, the best I can help is to point you to the official POSIX documentation on the subject.

    2.8.4 Process Scheduling - http://www.opengroup.org/onlinepubs/...l#tag_02_08_04
    pthread_[g|s]etschedparam - http://www.opengroup.org/onlinepubs/...chedparam.html
    pthread_setschedprio - http://www.opengroup.org/onlinepubs/...schedprio.html

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WIN32 API and Linux... *shudder
    By parad0x13 in forum C++ Programming
    Replies: 4
    Last Post: 07-24-2008, 07:27 PM
  2. Why Linux, for the average user?
    By Hunter2 in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 07-07-2006, 02:36 PM
  3. Linux
    By cerin in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 02-10-2005, 08:41 PM
  4. Linux Linux why Linux??
    By afreedboy in forum Tech Board
    Replies: 146
    Last Post: 01-21-2004, 05:27 PM
  5. Replies: 3
    Last Post: 10-29-2003, 08:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21