Pthread question

This is a discussion on Pthread question within the C Programming forums, part of the General Programming Boards category; Hi all, I'm not sure if it is the right place to ask questions about pthread but here's my problem. ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    2

    Pthread question

    Hi all,

    I'm not sure if it is the right place to ask questions about pthread but here's my problem.

    I'm trying to set the policy/priority for the threads. I read somewhere that I need to be superuser to change those info. Is that correct ? I tried the following:
    Code:
      status = pthread_attr_init (&thread_attr);
      fprintf (stderr, "pthread_attr_init returns %d\n", status);
      status = pthread_attr_setschedpolicy(&thread_attr, SCHED_FIFO);
      fprintf (stderr, "pthread_attr_setschedpolicy returns %d\n", status);
    
      status = pthread_attr_setinheritsched(&thread_attr, PTHREAD_EXPLICIT_SCHED);
    the status code of all the calls above are all 0's.

    However, when I do pthread_create, it returns a positive 1 and when I do
    Code:
          if (status == 1){
            perror ("pthread_create error");
            exit(1);
          }
    pthread_create error: Numerical result out of range
    If I remove pthread_attr_setinheritsched statement, the code runs to completion but just not changing the policy.

    Any suggestion/comments are welcome. Thank you in advanced

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Does this line also sets status to 0? Not clear, cause you don't have a fprintf() for this
    Code:
    status = pthread_attr_setinheritsched(&thread_attr, PTHREAD_EXPLICIT_SCHED);

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    2
    Quote Originally Posted by C_ntua View Post
    Does this line also sets status to 0? Not clear, cause you don't have a fprintf() for this
    Code:
    status = pthread_attr_setinheritsched(&thread_attr, PTHREAD_EXPLICIT_SCHED);
    Yea I am sure I have a printf statement for that line too, I just forgot to paste but that status is 0 too

  4. #4
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Post all the code, or at least the one that has pthread_create so people can spot the error

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The Pthread Hell
    By matott in forum Linux Programming
    Replies: 1
    Last Post: 04-10-2005, 06:59 AM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  3. pthread question
    By rotis23 in forum Linux Programming
    Replies: 10
    Last Post: 04-07-2004, 03:57 AM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

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