Trouble with PTHREAD

I am trying to run a program that creates POSIX threads and trying to assign priority to these events.

I am getting the error ‘Operation not Permitted’ whenever I try to create a new thread. This is a recent problem which had not occurred previously with SUSE so I am not sure why this application stopped running, but it stopped running after i re-installed the SUSE software. Maybe I forgot a package or something is the only thing that sounds reasonable.

I have tired this suggestion I found from an Ubuntu user on another thread which sounds reasonable but didn’t seem to fix the problem:

On my version of Ubuntu (and probably yours too) there’s also a hard limit of zero, so you can’t simply use ulimit or setrlimit to raise this. One way to raise the hard limit is to add a line to/etc/security/limits.conf like this (replacing <username> with your username):
<username> hard rtprio 99hen you should be able to use ulimit (from the shell) or setrlimit (from your program) to set the soft limit to the priority you need; alternatively, you could set that automatically by adding a second line to limits.conf, replacing hard with soft.

> ulimit -Hr # show hard limit
99
> ulimit -r
0
> ulimit -Sr 1 # set soft limit
> ulimit -r
1

The only thing we can see here that it “had not occurred previously with SUSE”. Which does not inform us of the version it worked with, nor of the version you use now where it doesn’t. In fact it does shed doubt about the fact if this is about openSUSE at all!

Can you please tell us if this is about openSUSE (and when it is about SLES/SLED, please go to https://forums.suse.com/) and when yes, which version.

Yes I should have mentioned the version, which is kernel 2.6.37.1-1.2-desktop, and I am using OpenSUSE 11.4 (not using SUSE, sorry for the confusion). I at one point had installed this version on a Hard Disk IDE and didn’t seem to have this problem. Now i have a new installation of the same version and it seems to fail. I have realized that I can create a thread as long as I don’t try to set attributes.

Fails, generates ‘Operation not permitted’:
pthread_attr_init(&attr);
if(pthread_create(&PeriodicLoopThreadID, &attr, &periodic_loop_thread, NULL) != 0)

Works:
if(pthread_create(&PeriodicLoopThreadID, NULL, &periodic_loop_thread, NULL) != 0)

I would like to use task scheduling an priority and use such functions to do so.

thanks
-Joe

Sorry that I tune in again with a post that does not bring you much further to a solution. I am not realy understanding what statements you write above. It could be some programming language (C or so). I have no doubt that you, being new here, looked a bit around at what happens here and you must have seen that we have different (sub)forums. This is of course so that people with different kinds of expertise can spend their time efficiently by checking those (sub)forums they are experts for, saving time by not going to those forums they think they can not really help.

Thus I wonder why you posted this in Applications (IMHO read installed programs) instead of in Developement > Programming/Scripting. Of course mentioning that you use C (or whatever it is) in your thread title, to draw the attention of your fellow C programmers.

Do you want me to move this post there?

BTW openSUSE 11.4 is already long out of support and not very may people will have it available anymore to replay your problem. Same of course for the kernel version. That may or may not be of interest for your problem, but I hope you are aware of this.

Thanks for the advice and sorry for the confusion. Please move the thread to the correct forum (Development > Programming/Scripting).

This will be moved to Programming/Scripting and is CLOSED for the moment.

MOved from Applications and open again.

On 2013-09-13 17:06, hcvv wrote:
>
> hcvv;2584593 Wrote:
>> This will be moved to Programming/Scripting and is CLOSED for the
>> moment.
> MOved from Applications and open again.

Just to note that openSUSE 11.4 is a supported version (it is an LTS).
It is just that instead of being supported directly by staffers, it is
supported by volunteers, under the name “Evergreen”. It is an openSUSE
project.

openSUSE:Evergreen

Please do not say that it is not supported, it is incorrect.


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

Please show exactly which values you set in attr. And use tag code for code snippets.

Here is a code snippet, the functions that affect the attributes structure which is fed to create the thread, when I leave out the attribute from the thread create function, then it seems to work fine. Not sure which parameters it has a problem with, I also tried without customizing the attr structure, just involing the initiation of the attributes, and this also failed.


    /* create the alive thread */
 
    pthread_attr_init(&attr);
    pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
    pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
    params.sched_priority = MY_ALIVE_THREAD_PRIORITY;
    pthread_attr_setschedparam(&attr, &params);
    if (pthread_create(&my_alive_thread_id, &attr, &my_alive_thread, NULL) != 0)
    {
        perror("error:");
        exit(1);
    }

SCHED_FIFO is real time priority so requires special privileges to set it. See man sched_setscheduler(2) for details.