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 7967061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:35:53+00:00 2026-06-04T06:35:53+00:00

I have created two threads and i want to see their priority after they

  • 0

I have created two threads and i want to see their priority after they are created :-
for this I have written the following code :-

   #include <iostream>
   #include <unistd.h>
   #include <pthread.h>
   #include <sched.h>
   #include <string.h>
   #include <errno.h>
   int main()
   { //something
     struct sched_param main_param, t1_param, t2_param;
     pthread_t t1, t2;
      int *sched1, *sched2;
     if (pthread_create(&t1, NULL, fn1, NULL) != 0) // inside fn1 thread sleeps in loop
      {
        std::cout << "couldn't create t1" << std::endl;
        return -1;
       }
     if (pthread_create(&t2, NULL, fn2, NULL) != 0)  //inside fn2 thread sleeps in loop
      {
        std::cout << "couldn't create t2" << std::endl;
        return -1;
      }

   if (pthread_getschedparam(t1, sched1, &t1_param) != 0) 
     {
       std::cout << "error setting priority for T1: (" << errno << "), " << 
        strerror(errno) << std::endl;
     }
  std::cout << "t1 thread will have a prio of " << t1_param.sched_priority << std::endl;
   if (pthread_getschedparam(t1, sched2, &t1_param) != 0) 
     {
       std::cout << "error setting priority for T1: (" << errno << "), " << 
       strerror(errno) << std::endl;
     }
   std::cout << "t2 thread will have a prio of " << t2_param.sched_priority <<std::endl;

 // something 
 } 

only when i add code related to pthread_getschedparam i am getting the segmentation fault else the code works fine . Am i doing something wrong here ? I even tried replacing arhument sched1 and sched2 by NULL

  • 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-04T06:35:54+00:00Added an answer on June 4, 2026 at 6:35 am

    You declared pointers sched1 and sched2 of type int* but never initialised those pointers. You need to allocate int variables and then pass pointers to those variables.

    Like this:

    int sched1, sched2;
    .....
    if (pthread_getschedparam(t1, &sched1, ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have created two objects from class foo and now want to
I have the following situation: I have two threads thread1 , which is a
I have an application where I want two users to communicate with eachother.. This
I have two threads (I am using pthreads on GNU/Linux). Now they are sharing
I have created two forms in my Windows Application. One Form acts as a
I have created two files: tunables.h #ifndef TUNABLES_H #define TUNABLES_H void tunables_load_conservative(); void tunables_load_aggressive();
I have created two JavaScript files. One file is "validators.js" and the other is
I have created two viewController classes such that one is superclass of another.i have
I have created two custom controls. On the basis of features any one of
I have created two functions that sum and subtract the numeric values of two

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.