Home > pthread attr setschedparam error > pthread_attr_setschedparam error

Pthread_attr_setschedparam Error

Contents

NAME top pthread_attr_setschedparam, pthread_attr_getschedparam - set/get scheduling parameter attributes in thread attributes object SYNOPSIS

Pthread_attr_setschedparam Example

top #include int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param); int pthread_attr_setschedpolicy pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param); Compile and link with -pthread. DESCRIPTION top

Pthread_attr_setinheritsched

The pthread_attr_setschedparam() function sets the scheduling parameter attributes of the thread attributes object referred to by attr to the values specified in the buffer pointed to by struct sched_param param. These attributes determine the scheduling parameters of a thread created using the thread attributes object attr. The pthread_attr_getschedparam() returns the scheduling parameter attributes of the thread attributes object attr in the buffer pointed to by param. Scheduling parameters are maintained in the following structure: struct sched_param { int sched_priority; /* Scheduling priority */ sched_priority }; As can be seen, only one scheduling parameter is supported. For details of the permitted ranges for scheduling priorities in each scheduling policy, see sched(7). In order for the parameter setting made by pthread_attr_setschedparam() to have effect when calling pthread_create(3), the caller must use pthread_attr_setinheritsched(3) to set the inherit-scheduler attribute of the attributes object attr to PTHREAD_EXPLICIT_SCHED. RETURN VALUE top On success, these functions return 0; on error, they return a nonzero error number. ERRORS top pthread_attr_setschedparam() can fail with the following error: EINVAL The priority specified in param does not make sense for the current scheduling policy of attr. POSIX.1 also documents an ENOTSUP error for pthread_attr_setschedparam(). This value is never returned on Linux (but portable and future-proof applications should nevertheless handle this error return value). ATTRIBUTES top For an explanation of the terms used in this section, see attributes(7). ┌──────────────────────────────┬───────────────┬─────────┐ │Interface │ Attribute │ Value │ ├──────────────────────────────┼

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business

Pthread Set Priority

Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs pthread_setschedparam Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just

Pthread_attr_init

like you, helping each other. Join them; it only takes a minute: Sign up pthread_create not working properly with pthread_attr_setschedparam up vote 1 down vote favorite 1 I am a novice in thread programming. So my apologies http://man7.org/linux/man-pages/man3/pthread_attr_getschedparam.3.html for this seemingly stupid question. I am trying to create a POSIX thread using pthread_create() using pthread_attr_t. I am trying to set the sched_priority value and put it in the attribute.The code is pasted below: #include #include #include using namespace std; void* log(void* arg) { FILE *fp = fopen("/tmp/log.txt", "w+"); if (fp != NULL) { fputs("Logging with Thread", fp); } else { cout <<"file pointer not created" << endl; } return 0; http://stackoverflow.com/questions/14989708/pthread-create-not-working-properly-with-pthread-attr-setschedparam } int main(int argc, char** argv ) { pthread_t th; pthread_attr_t th_attr; int policy; struct sched_param thparam; memset(&thparam, 0,sizeof(sched_param)); int retval = pthread_attr_init(&th_attr); if (0 != retval) { cout <<"Attribute initialization failed" << endl; } thparam.sched_priority = 10; int ret1 = pthread_attr_setschedparam(&th_attr, &thparam); if (0 == ret1) { cout <<"pthread_attr_setschedparam PASSED" << endl; } int ret = pthread_create(&th, &th_attr, log, NULL); if (0 != ret) { cout <<"thread not created" << endl; } else { cout <<"Thread created" << endl; } int retval1 = pthread_getschedparam(th, &policy, &thparam); if (0 != retval1) { cout <<"Inside Main::pthread_getschedparam FAILED at start" << endl; } else { cout <<"Inside Main::priority: " << thparam.sched_priority << endl; cout <<"Inside Main::sched policy: " << policy << endl; } pthread_join(th, NULL); return (0); } Every time I run this program, the thread gets created but the default priority (15 in my case).Since I have set the priority to 10 it should start with 10 priority. I can't understand why this is happening. All the log messages I am printing are as expected and there seem to be no error. Can anyone please point out what I am doing wrong in the code? Thanks!!!! EDIT: I seem to have found out a interesting thing.I was not able to set the thread priority during thread creation. But I can change the p

Log In [x] | Forgot Password Login: [x] Bug10828 - New check added in pthread_attr_setschedparam() causes hard-to-explain behavior Summary: New check added in pthread_attr_setschedparam() causes hard-to-explain behavior Status: RESOLVED DUPLICATE of bug 7013 Alias: None Product: glibc Classification: Unclassified Component: nptl (show other bugs) Version: 2.10 Importance: P2 normal Target Milestone: --- Assignee: Ulrich Drepper URL: Keywords: Depends on: Blocks: Reported: 2009-10-22 13:40 UTC by Jiri Dluhos Modified: 2014-07-01 05:35 UTC (History) CC List: 1 user (show) glibc-bugs See Also: Host: Target: Build: Last reconfirmed: Flags: fweimer: security- Attachments Add an attachment (proposed patch, testcase, etc.) Note You need to log in before you can comment on or make changes to this bug. Description Jiri Dluhos 2009-10-22 13:40:47 UTC (This problem was found by analyzing a failure of LSB distribution compliance test, lsb-runtime, v. 4.0.2.) A relatively new change in $GITROOT/glibc/nptl/pthread_attr_setschedparam.c (2009-04-23 according to git) adds a check to pthread_attr_setschedparam() call whether the priority being set is compatible with the scheduling policy already set in the structure; if the priority is not in the prescribed range, it fails, generating the EINVAL error. This check, although well intended, has a side effect that can break existing code (at least the LSB tests): it makes the process of initializing a pthread_attr structure order-dependent on Linux. As Linux does not use the numeric priority for SCHED_OTHER, which is the default, and sched_get_priority_min() and sched_priority_max() return 0. Therefore: If a programmer calls pthread_attr_init(), then pthread_attr_setschedpolicy() to set SCHED_RR or SCHED_FIFO, and then pthread_attr_setschedparam(), it works. But if the other way around (priority first, then scheduling policy), it fails for "no apparent reason". Comment 1 Ulrich Drepper 2009-10-22 13:52:08 UTC File a bug with the LSB, as usual their code is broken. Comment 2 Jiri Dluhos 2009-10-22 14:16:46 UTC I agree, LSB tests

 

Related content

No related pages.