Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8045659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:36:57+00:00 2026-06-05T05:36:57+00:00

I wanted to use read-writer locks from pthread library in a way, that writers

  • 0

I wanted to use read-writer locks from pthread library in a way, that writers have priority over readers. I read in my man pages that

If the Thread Execution Scheduling option is supported, and the threads involved in the lock are executing with the scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not acquire the lock if a writer holds the lock or if writers of higher or equal priority are blocked on the lock; otherwise, the calling thread shall acquire the lock.

so I wrote small function that sets up thread scheduling options.

void thread_set_up(int _thread)
{
 struct sched_param *_param=malloc(sizeof (struct sched_param));
 int *c=malloc(sizeof(int));
 *c=sched_get_priority_min(SCHED_FIFO)+1;
 _param->__sched_priority=*c;
 long *a=malloc(sizeof(long));
 *a=syscall(SYS_gettid);
 int *b=malloc(sizeof(int));
 *b=SCHED_FIFO;
 if (pthread_setschedparam(*a,*b,_param) == -1)
 {
    //depending on which thread calls this functions, few thing can happen
    if (_thread == MAIN_THREAD)
        client_cleanup();
    else if (_thread==ACCEPT_THREAD)
    {
        pthread_kill(params.main_thread_id,SIGINT);
        pthread_exit(NULL);
    }
}

}

sorry for those a,b,c but I tried to malloc everything, still I get SIGSEGV on the call to pthread_setschedparam, I am wondering why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:36:58+00:00Added an answer on June 5, 2026 at 5:36 am

    I don’t know if these are the exact causes of your problems but they should help you hone in on it.

    (1) pthread_setschedparam returns a 0 on success and a positive number otherwise. So

    if (pthread_setschedparam(*a,*b,_param) == -1) 
    

    will never execute. It should be something like:

    if ((ret = pthread_setschedparam(*a, *b, _param)) != 0)
    { //yada yada 
    }
    

    As an aside, it isn’t 100% clear what you are doing but pthread_kill looks about as ugly a way to do it as possible.

    (2) syscall(SYS_gettid) gets the OS threadID. pthread__setschedparam expects the pthreads thread id, which is different. The pthreads thread id is returned by pthread_create and pthread_self in the datatype pthread_t. Change the pthread__setschedparam to use this type and the proper values instead and see if things improve.

    (3) You need to run as a priviledge user to change the schedule. Try running the program as root or sudo or whatever.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've to read program log file and to do that I wanted to use
I wanted to use find to find every file in a directory that starts
I wanted to use monotouch, but unfortunately I don't have $400 to spend. So
In a program that I'm writing, I wanted to make a ConfigParser that's read
Can anyone recommend a simple API that will allow me to use read a
I am using Backbone and decided that I wanted a way to differentiate between
I wanted to use 6 different textures on a cube, one per side, but
I wanted to use full import names in my project (see this question ).
I wanted to use winreg module of python for working with windows registry. But
I wanted to use full width stripe on my footer, but aparently it doesen't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.