• pthread_attr_setinheritsched() not working on Linux

    From DozingDog@thekennel.co@21:1/5 to All on Thu Nov 25 11:12:47 2021
    For some reason the above function doesn't work in linux no matter what priority is used or what thread id is given yet it works perfectly in MacOS. Also on Linux using pthread_getschedparam() just returns a priority of zero.

    Anyone know why? Is there some attribute that needs to be set on Linux to
    allow priority setting to work?

    Here's some example test code:

    #include <stdio.h>
    #include <stdlib.h>
    #include <pthread.h>
    #include <string.h>
    #include <errno.h>

    void info()
    {
    struct sched_param param;
    pthread_t tid = pthread_self();
    int policy;

    if (pthread_getschedparam(tid,&policy,&param)) abort();
    printf("Policy = %d, priority = %d\n",policy,param.sched_priority);
    }


    void setPriority(pthread_t tid)
    {
    struct sched_param param;
    int cnt = 0;
    int i;
    for(i=1;i < 100;++i)
    {
    param.sched_priority = i;
    if (pthread_setschedparam(tid,SCHED_FIFO,&param))
    {
    printf("%d: %d,%s\n",i,errno,strerror(errno));
    ++cnt;
    }
    else printf("%d: SUCCESS\n",i);
    }
    printf("%d failures.\n",cnt);
    }



    void *func(void *p)
    {
    pthread_t tid = pthread_self();

    puts("Child thread:");
    info();
    setPriority(pthread_self());
    return NULL;
    }


    int main()
    {
    pthread_t tid;
    pthread_attr_t attr;

    puts("Parent thread:");
    setPriority(pthread_self());
    puts("---------------");
    pthread_attr_init(&attr);
    pthread_attr_setinheritsched(&attr,PTHREAD_EXPLICIT_SCHED);
    if (pthread_create(&tid,&attr,func,NULL) == -1) abort();
    pthread_join(tid,NULL);
    return 0;
    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Branimir Maksimovic@21:1/5 to DozingDog@thekennel.co on Thu Nov 25 15:13:45 2021
    On 2021-11-25, DozingDog@thekennel.co <DozingDog@thekennel.co> wrote:
    For some reason the above function doesn't work in linux no matter what priority is used or what thread id is given yet it works perfectly in MacOS. Also on Linux using pthread_getschedparam() just returns a priority of zero.

    Anyone know why? Is there some attribute that needs to be set on Linux to allow priority setting to work?

    Here's some example test code:

    #include <stdio.h>
    #include <stdlib.h>
    #include <pthread.h>
    #include <string.h>
    #include <errno.h>

    void info()
    {
    struct sched_param param;
    pthread_t tid = pthread_self();
    int policy;

    if (pthread_getschedparam(tid,&policy,&param)) abort();
    printf("Policy = %d, priority = %d\n",policy,param.sched_priority);
    }


    void setPriority(pthread_t tid)
    {
    struct sched_param param;
    int cnt = 0;
    int i;
    for(i=1;i < 100;++i)
    {
    param.sched_priority = i;
    if (pthread_setschedparam(tid,SCHED_FIFO,&param))
    {
    printf("%d: %d,%s\n",i,errno,strerror(errno));
    ++cnt;
    }
    else printf("%d: SUCCESS\n",i);
    }
    printf("%d failures.\n",cnt);
    }



    void *func(void *p)
    {
    pthread_t tid = pthread_self();

    puts("Child thread:");
    info();
    setPriority(pthread_self());
    return NULL;
    }


    int main()
    {
    pthread_t tid;
    pthread_attr_t attr;

    puts("Parent thread:");
    setPriority(pthread_self());
    puts("---------------");
    pthread_attr_init(&attr);
    pthread_attr_setinheritsched(&attr,PTHREAD_EXPLICIT_SCHED);
    if (pthread_create(&tid,&attr,func,NULL) == -1) abort();
    pthread_join(tid,NULL);
    return 0;
    }

    On Linux, there are different schedulers and thread is just another process, that shares same memory space. I would try process scehduling functions...

    --

    7-77-777
    Evil Sinner!
    with software, you repeat same experiment, expecting different results...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to DozingDog@thekennel.co on Thu Nov 25 15:37:07 2021
    DozingDog@thekennel.co writes:

    For some reason the above function doesn't work in linux no matter what priority is used or what thread id is given yet it works perfectly in MacOS. Also on Linux using pthread_getschedparam() just returns a priority of
    zero.

    It works when run as root. In general, since threads a essentially
    processes, you don't want any old code to be setting their priority.
    There may be a less heavy-handed way to achieve what you want, but I
    can't say what off the top of my head.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From DozingDog@thekennel.co@21:1/5 to Ben Bacarisse on Thu Nov 25 15:55:07 2021
    On Thu, 25 Nov 2021 15:37:07 +0000
    Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
    DozingDog@thekennel.co writes:

    For some reason the above function doesn't work in linux no matter what
    priority is used or what thread id is given yet it works perfectly in MacOS. >> Also on Linux using pthread_getschedparam() just returns a priority of
    zero.

    It works when run as root. In general, since threads a essentially

    Not for me.

    processes, you don't want any old code to be setting their priority.

    Threads haven't mapped 1:1 to processes since the 2.4 kernel. Yes if you
    only have 1 thread it'll just be the main process but multiple threads will exist within that process and we need to set the priority of individual
    threads WITHIN the process.

    There may be a less heavy-handed way to achieve what you want, but I
    can't say what off the top of my head.

    If the posix thread priority functionality doesn't work in linux , at least as a normal user, thats a large chunk of missing functionality.

    thread priority != process nice level

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From DozingDog@thekennel.co@21:1/5 to Branimir Maksimovic on Thu Nov 25 15:55:49 2021
    On Thu, 25 Nov 2021 15:13:45 GMT
    Branimir Maksimovic <branimir.maksimovic@icloud.com> wrote:
    On Linux, there are different schedulers and thread is just another process, >that shares same memory space. I would try process scehduling functions...

    This is thread priority within a process, not process priority within the OS.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to DozingDog@thekennel.co on Thu Nov 25 20:44:03 2021
    DozingDog@thekennel.co writes:

    On Thu, 25 Nov 2021 15:37:07 +0000
    Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
    DozingDog@thekennel.co writes:

    For some reason the above function doesn't work in linux no matter what
    priority is used or what thread id is given yet it works perfectly in MacOS.
    Also on Linux using pthread_getschedparam() just returns a priority of
    zero.

    It works when run as root. In general, since threads a essentially

    Not for me.

    Oh well, at least you have another data point.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rainer Weikusat@21:1/5 to Branimir Maksimovic on Thu Nov 25 20:25:08 2021
    Branimir Maksimovic <branimir.maksimovic@icloud.com> writes:

    [...]

    On Linux, there are different schedulers and thread is just another process, that shares same memory space.

    SUS defines (live) process as

    An address space with one or more threads executing within that address
    space, and the required system resources for those threads.

    Linux employs a so-called 1:1 threading model which means every thread
    is scheduled by the kernel scheduler.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to DozingDog@thekennel.co on Sat Nov 27 17:05:07 2021
    DozingDog@thekennel.co writes:

    On Sat, 27 Nov 2021 16:27:11 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    DozingDog@thekennel.co writes:
    For some reason the above function doesn't work in linux no matter what >>>priority is used or what thread id is given yet it works perfectly in MacOS. >>>Also on Linux using pthread_getschedparam() just returns a priority of zero. >>>
    Anyone know why? Is there some attribute that needs to be set on Linux to >>>allow priority setting to work?

    An unprivileged process can only reduce (lessen) its priority. Only
    a privileged process can raise (increase) its priority.

    I'm talking about thread priorities within a process, not process priorities within the OS.

    I think your information (or your Linux) is out of date. Threads are
    scheduled by the kernel in the same way as processes (in effect they are processes), though the whole topic is very complicated. (For example,
    the prioroty can be set to relative to a thread group. I don't pretend
    to know the ins and outs.)

    In sched(7) you will find:

    According to POSIX.1, the nice value is a per-process attribute; that
    is, the threads in a process should share a nice value. However, on
    Linux, the nice value is a per-thread attribute: different threads in
    the same process may have different nice values.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to DozingDog@thekennel.co on Sat Nov 27 16:27:11 2021
    DozingDog@thekennel.co writes:
    For some reason the above function doesn't work in linux no matter what >priority is used or what thread id is given yet it works perfectly in MacOS. >Also on Linux using pthread_getschedparam() just returns a priority of zero.

    Anyone know why? Is there some attribute that needs to be set on Linux to >allow priority setting to work?

    An unprivileged process can only reduce (lessen) its priority. Only
    a privileged process can raise (increase) its priority.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From DozingDog@thekennel.co@21:1/5 to Scott Lurndal on Sat Nov 27 16:47:21 2021
    On Sat, 27 Nov 2021 16:27:11 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    DozingDog@thekennel.co writes:
    For some reason the above function doesn't work in linux no matter what >>priority is used or what thread id is given yet it works perfectly in MacOS. >>Also on Linux using pthread_getschedparam() just returns a priority of zero. >>
    Anyone know why? Is there some attribute that needs to be set on Linux to >>allow priority setting to work?

    An unprivileged process can only reduce (lessen) its priority. Only
    a privileged process can raise (increase) its priority.

    I'm talking about thread priorities within a process, not process priorities within the OS.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From DozingDog@thekennel.co@21:1/5 to Ben Bacarisse on Sat Nov 27 18:17:29 2021
    On Sat, 27 Nov 2021 17:05:07 +0000
    Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
    DozingDog@thekennel.co writes:

    On Sat, 27 Nov 2021 16:27:11 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    DozingDog@thekennel.co writes:
    For some reason the above function doesn't work in linux no matter what >>>>priority is used or what thread id is given yet it works perfectly in MacOS.

    Also on Linux using pthread_getschedparam() just returns a priority of zero.


    Anyone know why? Is there some attribute that needs to be set on Linux to >>>>allow priority setting to work?

    An unprivileged process can only reduce (lessen) its priority. Only
    a privileged process can raise (increase) its priority.

    I'm talking about thread priorities within a process, not process priorities >> within the OS.

    I think your information (or your Linux) is out of date. Threads are >scheduled by the kernel in the same way as processes (in effect they are >processes), though the whole topic is very complicated. (For example,
    the prioroty can be set to relative to a thread group. I don't pretend
    to know the ins and outs.)

    In sched(7) you will find:

    According to POSIX.1, the nice value is a per-process attribute; that
    is, the threads in a process should share a nice value. However, on
    Linux, the nice value is a per-thread attribute: different threads in
    the same process may have different nice values.

    Fair enough. Still doesn't explain why the function in the subject line doesn't work no matter what value you give it. Also its valid value range doesn't
    match that of process priorities.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to DozingDog@thekennel.co on Sat Nov 27 20:48:22 2021
    DozingDog@thekennel.co writes:

    On Sat, 27 Nov 2021 17:05:07 +0000
    Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
    DozingDog@thekennel.co writes:

    On Sat, 27 Nov 2021 16:27:11 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    DozingDog@thekennel.co writes:
    For some reason the above function doesn't work in linux no matter what >>>>>priority is used or what thread id is given yet it works perfectly in MacOS.

    Also on Linux using pthread_getschedparam() just returns a priority of zero.


    Anyone know why? Is there some attribute that needs to be set on Linux to >>>>>allow priority setting to work?

    An unprivileged process can only reduce (lessen) its priority. Only
    a privileged process can raise (increase) its priority.

    I'm talking about thread priorities within a process, not process priorities
    within the OS.

    I think your information (or your Linux) is out of date. Threads are >>scheduled by the kernel in the same way as processes (in effect they are >>processes), though the whole topic is very complicated. (For example,
    the prioroty can be set to relative to a thread group. I don't pretend
    to know the ins and outs.)

    In sched(7) you will find:

    According to POSIX.1, the nice value is a per-process attribute; that
    is, the threads in a process should share a nice value. However, on
    Linux, the nice value is a per-thread attribute: different threads in
    the same process may have different nice values.

    Fair enough. Still doesn't explain why the function in the subject line doesn't
    work no matter what value you give it.

    Since it worked for me (under sudo) I am not sure what needs explaining.
    It did not work for you, but the details on that were very sparse.

    Also its valid value range doesn't
    match that of process priorities.

    Did you read sched(7)? Does the process have suitable privileges?

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to DozingDog@thekennel.co on Sat Nov 27 16:44:17 2021
    On 11/25/21 10:55 AM, DozingDog@thekennel.co wrote:
    On Thu, 25 Nov 2021 15:37:07 +0000
    Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
    DozingDog@thekennel.co writes:

    For some reason the above function doesn't work in linux no matter what
    priority is used or what thread id is given yet it works perfectly in MacOS.
    Also on Linux using pthread_getschedparam() just returns a priority of
    zero.

    It works when run as root. In general, since threads a essentially

    Not for me.

    Since it works for Ben, and doesn't work for you, an important question
    that only you can answer is, how does it fail for you?

    It's permitted to fail. If it does, it should return a non-zero value
    and set errno to either ENOTSUP or EINVAL. If you change your call to

    if(pthread_attr_setinheritsched(&attr,PTHREAD_EXPLICIT_SCHED)){
    perror("pthread_attr_setinheritsched");
    }

    What results do you get?

    Since you didn't check for that return value, and still managed to
    conclude that it wasn't working, I presume that you're using some other
    piece of evidence that it didn't work; presumably something happened
    that you wouldn't have expected if it had worked. What was that something?

    The kind of program that needs to call that function is likely to be
    very complicated, but if you can simplify the program down to a small, compileable program that demonstrates what went wrong, and then tell us precisely what results you got from running that program, it would make
    it a lot easier for people to help you.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to James Kuyper on Sat Nov 27 22:18:23 2021
    James Kuyper <jameskuyper@alumni.caltech.edu> writes:

    On 11/25/21 10:55 AM, DozingDog@thekennel.co wrote:
    On Thu, 25 Nov 2021 15:37:07 +0000
    Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
    DozingDog@thekennel.co writes:

    For some reason the above function doesn't work in linux no matter what >>>> priority is used or what thread id is given yet it works perfectly in MacOS.
    Also on Linux using pthread_getschedparam() just returns a priority of >>>> zero.

    It works when run as root. In general, since threads a essentially

    Not for me.

    Since it works for Ben, and doesn't work for you, an important question
    that only you can answer is, how does it fail for you?

    To be honest, another question is how does it work for me? I just saw
    lost of lines with, IIRC, "SUCCESS" in them.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to DozingDog@thekennel.co on Sun Nov 28 00:19:36 2021
    DozingDog@thekennel.co writes:
    On Sat, 27 Nov 2021 16:27:11 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    DozingDog@thekennel.co writes:
    For some reason the above function doesn't work in linux no matter what >>>priority is used or what thread id is given yet it works perfectly in MacOS. >>>Also on Linux using pthread_getschedparam() just returns a priority of zero. >>>
    Anyone know why? Is there some attribute that needs to be set on Linux to >>>allow priority setting to work?

    An unprivileged process can only reduce (lessen) its priority. Only
    a privileged process can raise (increase) its priority.

    I'm talking about thread priorities within a process, not process priorities >within the OS.


    As was pointed out to you, linux threads are light-weight processes
    implemented as an 1:1 threading model.

    The last M:N threading model I worked with was Unixware, and even there,
    a thread couldn't have a priority higher than the process priority
    unless it was part of a privileged process.

    Leaving aside the details, allowing arbitrary control of the priority
    of schedulable entities is rather unfriendly on a multiuser or multi
    tenant system.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From DozingDog@thekennel.co@21:1/5 to Ben Bacarisse on Mon Nov 29 10:11:22 2021
    On Sat, 27 Nov 2021 20:48:22 +0000
    Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
    DozingDog@thekennel.co writes:

    On Sat, 27 Nov 2021 17:05:07 +0000
    Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
    DozingDog@thekennel.co writes:

    On Sat, 27 Nov 2021 16:27:11 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    DozingDog@thekennel.co writes:
    For some reason the above function doesn't work in linux no matter what >>>>>>priority is used or what thread id is given yet it works perfectly in >MacOS.

    Also on Linux using pthread_getschedparam() just returns a priority of >zero.


    Anyone know why? Is there some attribute that needs to be set on Linux to >>>>>>allow priority setting to work?

    An unprivileged process can only reduce (lessen) its priority. Only >>>>>a privileged process can raise (increase) its priority.

    I'm talking about thread priorities within a process, not process >priorities
    within the OS.

    I think your information (or your Linux) is out of date. Threads are >>>scheduled by the kernel in the same way as processes (in effect they are >>>processes), though the whole topic is very complicated. (For example, >>>the prioroty can be set to relative to a thread group. I don't pretend >>>to know the ins and outs.)

    In sched(7) you will find:

    According to POSIX.1, the nice value is a per-process attribute; that
    is, the threads in a process should share a nice value. However, on
    Linux, the nice value is a per-thread attribute: different threads in
    the same process may have different nice values.

    Fair enough. Still doesn't explain why the function in the subject line >doesn't
    work no matter what value you give it.

    Since it worked for me (under sudo) I am not sure what needs explaining.
    It did not work for you, but the details on that were very sparse.

    Thats because I don't have many. Oddly I tried it on a very old distro
    (2016 with 4.4 kernel) I have on an old laptop and it did work albeit with sudo.

    Also its valid value range doesn't
    match that of process priorities.

    Did you read sched(7)? Does the process have suitable privileges?

    Yes, gave me a headache frankly. Confusing is one way of describing it.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From DozingDog@thekennel.co@21:1/5 to James Kuyper on Mon Nov 29 10:14:19 2021
    On Sat, 27 Nov 2021 16:44:17 -0500
    James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
    On 11/25/21 10:55 AM, DozingDog@thekennel.co wrote:
    On Thu, 25 Nov 2021 15:37:07 +0000
    Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
    DozingDog@thekennel.co writes:

    For some reason the above function doesn't work in linux no matter what >>>> priority is used or what thread id is given yet it works perfectly in >MacOS.
    Also on Linux using pthread_getschedparam() just returns a priority of >>>> zero.

    It works when run as root. In general, since threads a essentially

    Not for me.

    Since it works for Ben, and doesn't work for you, an important question
    that only you can answer is, how does it fail for you?

    It's permitted to fail. If it does, it should return a non-zero value
    and set errno to either ENOTSUP or EINVAL. If you change your call to

    if(pthread_attr_setinheritsched(&attr,PTHREAD_EXPLICIT_SCHED)){
    perror("pthread_attr_setinheritsched");
    }

    What results do you get?

    No error, works ok.

    The kind of program that needs to call that function is likely to be
    very complicated, but if you can simplify the program down to a small,

    It is, its a work project. Luckily the boss has lost interest in setting
    thread piorities for now.

    compileable program that demonstrates what went wrong, and then tell us >precisely what results you got from running that program, it would make
    it a lot easier for people to help you.

    I did, that was the test code.

    Anyway, I no longer have to worry about it but thanks for the help.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From DozingDog@thekennel.co@21:1/5 to Scott Lurndal on Mon Nov 29 10:16:13 2021
    On Sun, 28 Nov 2021 00:19:36 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    DozingDog@thekennel.co writes:
    On Sat, 27 Nov 2021 16:27:11 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    DozingDog@thekennel.co writes:
    For some reason the above function doesn't work in linux no matter what >>>>priority is used or what thread id is given yet it works perfectly in MacOS.

    Also on Linux using pthread_getschedparam() just returns a priority of zero.


    Anyone know why? Is there some attribute that needs to be set on Linux to >>>>allow priority setting to work?

    An unprivileged process can only reduce (lessen) its priority. Only
    a privileged process can raise (increase) its priority.

    I'm talking about thread priorities within a process, not process priorities >>within the OS.


    As was pointed out to you, linux threads are light-weight processes >implemented as an 1:1 threading model.

    They're still within the same process with the same process ID.

    The last M:N threading model I worked with was Unixware, and even there,
    a thread couldn't have a priority higher than the process priority
    unless it was part of a privileged process.

    Leaving aside the details, allowing arbitrary control of the priority
    of schedulable entities is rather unfriendly on a multiuser or multi
    tenant system.

    I was under the impression that setting a threads priority set the
    priority of thread IN THAT PROCESS, it didn't set the priority of the
    thread wrt the OS. The latter is the "nice" level.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Douglas Wells@21:1/5 to jameskuyper@alumni.caltech.edu on Mon Nov 29 10:11:33 2021
    In article <snu8rh$h0s$1@dont-email.me>,
    James Kuyper <jameskuyper@alumni.caltech.edu> wrote:

    It's permitted to fail. If it does, it should return a non-zero value >[pthread_attr_setinheritsched is] permitted to fail. If it does, it should return a non-zero value
    and set errno to either ENOTSUP or EINVAL. If you change your call to

    if(pthread_attr_setinheritsched(&attr,PTHREAD_EXPLICIT_SCHED)){
    perror("pthread_attr_setinheritsched");
    }

    Please allow me to make a subtle correction to the above explanation.

    The pthread API generally behaves differently than most other
    POSIX/UNIX functions. In particular, the "non-zero value" that is
    often returned IS the error number. Specifically, the errno
    variable is NOT set. Failure to recognize this can lead to some
    very confusing debugging sessions.

    Depending on whether the procedure invoking the pthread call is
    allowed (per its specification) to modify errno, the above example
    might be replaced by (untested):

    if((errno=pthread_attr_setinheritsched(&attr,PTHREAD_EXPLICIT_SCHED))){
    perror("pthread_attr_setinheritsched");
    }

    Simplistic explanation: The pthread API was developed over a number
    of years, originally under the auspices of the Real Time UNIX Symposia
    and later under the POSIX real-time group (IEEE 1003.4). There were
    two very active communities battling back and forth:

    1) Those who saw pthreads as simply an ordinary enhancement to the
    facilities of Unix. They wanted the pthread functions to behave as
    other Unix functions, and therefore should set errno. and

    2) Developers of small, embedded systems. This group foresaw the
    difficulties and overhead associated with the use of the errno
    "variable" in a threaded environment(*), and wished to avoid such
    difficulties in their constrained environments.

    Providing the error number as a return result was the ensuing
    compromise.

    (*) The errno "variable" is required to be maintained on a per-thread
    basis. The pthread API was created over a quarter century ago, long
    before the invention of POSIX per-thread variables. The
    implementation of errno in modern systems using pthreads often
    involves a procedure invocation for each use of errno. The resulting
    overhead is high enough that some systems detect the non-use of
    pthreads and then replace the general, but expensive, mechanism with
    the simple use of a global shared variable, mimicking the
    implementation of errno in historic Unix.

    - dmw

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to DozingDog@thekennel.co on Mon Nov 29 14:44:21 2021
    DozingDog@thekennel.co writes:
    On Sun, 28 Nov 2021 00:19:36 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    DozingDog@thekennel.co writes:
    On Sat, 27 Nov 2021 16:27:11 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    DozingDog@thekennel.co writes:
    For some reason the above function doesn't work in linux no matter what >>>>>priority is used or what thread id is given yet it works perfectly in MacOS.

    Also on Linux using pthread_getschedparam() just returns a priority of zero.


    Anyone know why? Is there some attribute that needs to be set on Linux to >>>>>allow priority setting to work?

    An unprivileged process can only reduce (lessen) its priority. Only
    a privileged process can raise (increase) its priority.

    I'm talking about thread priorities within a process, not process priorities >>>within the OS.


    As was pointed out to you, linux threads are light-weight processes >>implemented as an 1:1 threading model.

    They're still within the same process with the same process ID.

    They are independently scheduled by the kernel. From the kernel
    point of view, they are separate processes sharing an address space
    and some process-global data. Technically, they're "clone" processes.


    The last M:N threading model I worked with was Unixware, and even there,
    a thread couldn't have a priority higher than the process priority
    unless it was part of a privileged process.

    Leaving aside the details, allowing arbitrary control of the priority
    of schedulable entities is rather unfriendly on a multiuser or multi
    tenant system.

    I was under the impression that setting a threads priority set the
    priority of thread IN THAT PROCESS, it didn't set the priority of the
    thread wrt the OS. The latter is the "nice" level.

    That depends on the threading model (1:1 vs. M:N) - in the later, there
    is a user-level scheduler which is constrained by the process priority;
    in the former, each thread is scheduled by the kernel. Experience with
    SVR4.2 ES/MP (and subsequently Unixware 2) showed that a user-level scheduler was complicated and provided little, if any, performance benefit.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From DozingDog@thekennel.co@21:1/5 to James Kuyper on Mon Nov 29 16:53:30 2021
    On Mon, 29 Nov 2021 11:17:48 -0500
    James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
    On 11/29/21 5:14 AM, DozingDog@thekennel.co wrote:
    On Sat, 27 Nov 2021 16:44:17 -0500
    James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
    ....
    compileable program that demonstrates what went wrong, and then tell us
    precisely what results you got from running that program, it would make
    it a lot easier for people to help you.

    I did, that was the test code.

    Sorry. I've given out that advice so often that I just wrote it out
    without stopping to think about the parts that weren't relevant to your
    case. However, you didn't complete the last part: you didn't tell us
    what results you actually got. You only told us that it didn't work.

    Operation not permitted is the error, rather than Permission denied. Which
    is curious.

    If you're no longer interested in this issue, feel free to ignore my
    request. However, keep in it mind the next time you ask for help: you
    should always include the unexpected output that you observed, if you
    can, along with an explanation of what it was you did expect (often,
    it's your expectations that are incorrect, rather than the output of the
    code - and sometimes both need correction).

    Basically we inherited some code that attempts to set the thread priority.
    It was noticed recently that this functionality isn't working but we have no idea if it ever worked (perhaps on an in house kernel build?) One would assume the original dev (long since left the company) might have noticed if it didn't but who knows? The process NEVER runs as root so its not a permissions issue in that sense.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From DozingDog@thekennel.co@21:1/5 to Scott Lurndal on Mon Nov 29 16:49:18 2021
    On Mon, 29 Nov 2021 14:44:21 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    DozingDog@thekennel.co writes:
    I was under the impression that setting a threads priority set the
    priority of thread IN THAT PROCESS, it didn't set the priority of the >>thread wrt the OS. The latter is the "nice" level.

    That depends on the threading model (1:1 vs. M:N) - in the later, there
    is a user-level scheduler which is constrained by the process priority;
    in the former, each thread is scheduled by the kernel. Experience with >SVR4.2 ES/MP (and subsequently Unixware 2) showed that a user-level scheduler >was complicated and provided little, if any, performance benefit.

    Its not about performance benefits, its more a case of sensible resource utilisation. Eg: if I have 2 threads, one doing CPU bound calculations and
    the other flashing a cursor and occasionally dealing with user input then I'd want the former to have higher priority IN THE PROCESS than the latter.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to DozingDog@thekennel.co on Mon Nov 29 11:18:14 2021
    On 11/29/21 5:11 AM, DozingDog@thekennel.co wrote:
    On Sat, 27 Nov 2021 20:48:22 +0000
    Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
    ...
    Since it worked for me (under sudo) I am not sure what needs explaining.
    It did not work for you, but the details on that were very sparse.

    Thats because I don't have many.

    For precisely that reason, it should have been easy to provide all the
    details you did have - specifically, what the actual output of your test program was.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to DozingDog@thekennel.co on Mon Nov 29 11:17:48 2021
    On 11/29/21 5:14 AM, DozingDog@thekennel.co wrote:
    On Sat, 27 Nov 2021 16:44:17 -0500
    James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
    ...
    compileable program that demonstrates what went wrong, and then tell us
    precisely what results you got from running that program, it would make
    it a lot easier for people to help you.

    I did, that was the test code.

    Sorry. I've given out that advice so often that I just wrote it out
    without stopping to think about the parts that weren't relevant to your
    case. However, you didn't complete the last part: you didn't tell us
    what results you actually got. You only told us that it didn't work.

    You should provide the full output of the program, that was not what you expected, along with an explanation of what you did expect to see. When
    I say "exact", I mean that you should ideally cut-and-paste it directly
    into your message, rather than retyping it by hand.

    Anyway, I no longer have to worry about it but thanks for the help.

    If you're no longer interested in this issue, feel free to ignore my
    request. However, keep in it mind the next time you ask for help: you
    should always include the unexpected output that you observed, if you
    can, along with an explanation of what it was you did expect (often,
    it's your expectations that are incorrect, rather than the output of the
    code - and sometimes both need correction).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to DozingDog@thekennel.co on Mon Nov 29 17:10:44 2021
    DozingDog@thekennel.co writes:
    On Mon, 29 Nov 2021 14:44:21 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    DozingDog@thekennel.co writes:
    I was under the impression that setting a threads priority set the >>>priority of thread IN THAT PROCESS, it didn't set the priority of the >>>thread wrt the OS. The latter is the "nice" level.

    That depends on the threading model (1:1 vs. M:N) - in the later, there
    is a user-level scheduler which is constrained by the process priority;
    in the former, each thread is scheduled by the kernel. Experience with >>SVR4.2 ES/MP (and subsequently Unixware 2) showed that a user-level scheduler >>was complicated and provided little, if any, performance benefit.

    Its not about performance benefits, its more a case of sensible resource >utilisation. Eg: if I have 2 threads, one doing CPU bound calculations and >the other flashing a cursor and occasionally dealing with user input then I'd >want the former to have higher priority IN THE PROCESS than the latter.


    Why don't you _reduce_ the priority of the cpu bound thread then? That's always nice and legal (pun intended).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Nicolas George@21:1/5 to All on Mon Nov 29 18:01:17 2021
    DozingDog@thekennel.co, dans le message <so30ae$1e8j$1@gioia.aioe.org>,
    a écrit :
    Eg: if I have 2 threads, one doing CPU bound calculations and
    the other flashing a cursor and occasionally dealing with user input then I'd want the former to have higher priority IN THE PROCESS than the latter.

    AFAIK, the scheduler of modern operating systems already does that automatically: it identifies CPU-bound and interactive processes and gives higher priority to interactivity.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rainer Weikusat@21:1/5 to Scott Lurndal on Mon Nov 29 17:43:45 2021
    scott@slp53.sl.home (Scott Lurndal) writes:
    DozingDog@thekennel.co writes:
    On Sun, 28 Nov 2021 00:19:36 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    DozingDog@thekennel.co writes:
    On Sat, 27 Nov 2021 16:27:11 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    DozingDog@thekennel.co writes:
    For some reason the above function doesn't work in linux no matter what >>>>>>priority is used or what thread id is given yet it works perfectly in MacOS.

    Also on Linux using pthread_getschedparam() just returns a priority of zero.


    Anyone know why? Is there some attribute that needs to be set on Linux to >>>>>>allow priority setting to work?

    An unprivileged process can only reduce (lessen) its priority. Only >>>>>a privileged process can raise (increase) its priority.

    I'm talking about thread priorities within a process, not process priorities
    within the OS.


    As was pointed out to you, linux threads are light-weight processes >>>implemented as an 1:1 threading model.

    They're still within the same process with the same process ID.

    They are independently scheduled by the kernel. From the kernel
    point of view, they are separate processes sharing an address space
    and some process-global data. Technically, they're "clone" processes.

    Separate processes sharing an address space is a contradictio in
    adiecto as the definition of process is

    An address space with one or more threads executing within that
    address space, and the required system resources for those
    threads.

    That's not consistent with the historic, empirical definition of process
    as a certain kernel-level abstraction which exists in
    UNIX-the-program. But applying that to Linux makes no sense as Linux is
    not something derived from the UNIX codebase. The Linux term is "kernel
    thread" and the Linux kernel employs kernel threads for a number of
    things, NPTL threads (and LinuxThreads before them) being among them.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Nicolas George@21:1/5 to All on Mon Nov 29 18:06:20 2021
    Scott Lurndal, dans le message <oQ7pJ.36491$1d1.25520@fx99.iad>, a
    écrit :
    Why don't you _reduce_ the priority of the cpu bound thread then? That's always nice and legal (pun intended).

    It has the consequence to lower the priority of the CPU-bound process
    relative to all other CPU-bound processes who did not have the same courtesy and are happily guzzling the CPU.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From DozingDog@thekennel.co@21:1/5 to Rainer Weikusat on Tue Nov 30 11:35:18 2021
    On Mon, 29 Nov 2021 17:43:45 +0000
    Rainer Weikusat <rweikusat@talktalk.net> wrote:
    scott@slp53.sl.home (Scott Lurndal) writes:
    They are independently scheduled by the kernel. From the kernel
    point of view, they are separate processes sharing an address space
    and some process-global data. Technically, they're "clone" processes.

    Separate processes sharing an address space is a contradictio in
    adiecto as the definition of process is

    An address space with one or more threads executing within that
    address space, and the required system resources for those
    threads.

    That's not consistent with the historic, empirical definition of process
    as a certain kernel-level abstraction which exists in
    UNIX-the-program. But applying that to Linux makes no sense as Linux is
    not something derived from the UNIX codebase. The Linux term is "kernel

    To be fair you could say the same about large parts of *BSD. It depends how
    you define "unix" and how far back in time you want to go.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From DozingDog@thekennel.co@21:1/5 to Nicolas George on Tue Nov 30 11:35:51 2021
    On 29 Nov 2021 18:01:17 GMT
    Nicolas George <nicolas$george@salle-s.org> wrote:
    DozingDog@thekennel.co, dans le message <so30ae$1e8j$1@gioia.aioe.org>,
    a écrit :
    Eg: if I have 2 threads, one doing CPU bound calculations and
    the other flashing a cursor and occasionally dealing with user input then I'd

    want the former to have higher priority IN THE PROCESS than the latter.

    AFAIK, the scheduler of modern operating systems already does that >automatically: it identifies CPU-bound and interactive processes and gives >higher priority to interactivity.

    Yes ok, possibly a poor example on my part. But you see the point I'm trying
    to make.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From DozingDog@thekennel.co@21:1/5 to Scott Lurndal on Tue Nov 30 11:33:17 2021
    On Mon, 29 Nov 2021 17:10:44 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    DozingDog@thekennel.co writes:
    On Mon, 29 Nov 2021 14:44:21 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    DozingDog@thekennel.co writes:
    I was under the impression that setting a threads priority set the >>>>priority of thread IN THAT PROCESS, it didn't set the priority of the >>>>thread wrt the OS. The latter is the "nice" level.

    That depends on the threading model (1:1 vs. M:N) - in the later, there >>>is a user-level scheduler which is constrained by the process priority; >>>in the former, each thread is scheduled by the kernel. Experience with >>>SVR4.2 ES/MP (and subsequently Unixware 2) showed that a user-level scheduler

    was complicated and provided little, if any, performance benefit.

    Its not about performance benefits, its more a case of sensible resource >>utilisation. Eg: if I have 2 threads, one doing CPU bound calculations and >>the other flashing a cursor and occasionally dealing with user input then I'd >>want the former to have higher priority IN THE PROCESS than the latter.


    Why don't you _reduce_ the priority of the cpu bound thread then? That's >always nice and legal (pun intended).

    The problem is Linux doesn't seem to accept ANY thread priority value, even the minimum, when the process isn't being run as root (and sometimes not even then).

    I get the feeling this functionality is a rather obscure corner of posix and possibly isn't supported as well as it should be on linux though it works fine on MacOS (and I so presume *BSD too).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)