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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:26:58+00:00 2026-05-15T19:26:58+00:00

Assume that the following code is being executed by 10 threads. pthread_mutex_lock(&lock) Some trivial

  • 0

Assume that the following code is being executed by 10 threads.

pthread_mutex_lock(&lock)
Some trivial code
pthread_mutex_unlock(&lock)

For purpose of explanations lets say the threads are T1, T2, T3…..T10.
My requirement is that as long as T1 or T2 or T3( i.e any of T1, T2 or T3) is waiting for acquiring a lock, the other threads i.t T4, T5, T6…..T10 should not be able to acquire the lock i.e T1, T2 and T3 should have precedence in acquiring the lock with respect to other threads.

I guess it could be done by increasing the priority of threads T1, T2 and T3

i.e here is the pseudo code

if this thread is T1 or T2 or T3
increase its priority 
pthread_mutex_lock(&lock)
Some trivial code
pthread_mutex_unlock(&lock)
if this thread is T1 or T2 or T3 decrease it priority to normal

Please note that I want a solution that is works for Linux platform and should use pthreads. I don’t really care about any other platform.

Also note that I don’t really want to make these 3 threads as realtime, I want them to exhibit their defualt behaviour(scheduling and priority) except that in the above mentioned small piece of code I want them to always have precedence in acquiring lock.

I have read some man pages about scheduling policies and scheduling priorities in Linux but can’t really make out 🙁

Will this work? Can you help me with the exact pthread API required to accomplish the above task?

Regards
lali

  • 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-05-15T19:26:59+00:00Added an answer on May 15, 2026 at 7:26 pm

    As I understand it, the only way you can truly guarantee this would be to write a lock that works like that yourself. However @xryl669’s answer that suggests using thread priority and priority inheritance is certainly worthy of consideration if it works for your use case.

    To implement it yourself, you will need condition variables and counts of the number of waiting low / high priority threads.

    In terms of the concepts and APIs you’ll need, it is relatively similar to implementing a read/write lock (but the semantics you need are completely different, obviously – but if you understood how the r/w lock is working, you’ll understand how to implement what you want).

    You can see an implementation of a read write lock here:

    http://ptgmedia.pearsoncmg.com/images/0201633922/sourcecode/rwlock.c

    In the lower priority threads, you’d need to wait for high priority threads to finish, in the same way readers wait for writers to finish.

    (The book the above code is taken from it also a great posix threads book btw, http://www.informit.com/store/product.aspx?isbn=0201633922 )

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

Sidebar

Ask A Question

Stats

  • Questions 509k
  • Answers 509k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You are hiding the method in the derived class. The… May 16, 2026 at 4:38 pm
  • Editorial Team
    Editorial Team added an answer Seems like you're using membership. Something like... http://dotnetblogger.com/post/2010/01/11/ASPNET-Membership-Remember-Me-That-Actually-Works.aspx should work.… May 16, 2026 at 4:38 pm
  • Editorial Team
    Editorial Team added an answer Aside from the fact that you will learn a lot… May 16, 2026 at 4:38 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Assume the following code, without any ref keyword, that obviously won't replace the variable
I have the following code that responds to a button click, changes the view
DISCLAIMER: The following code is not something I would ever use in a real
I read somewhere (and have observed) that starting threads is slow. I always assumed
In the following jquery function, can someone explain to me why second is being
Let's assume the following: I have an IIS web site set up IIS is
I have code similar to the following in a header file: template<class A> class
Let's assume we have the following class : public class ImageButton extends MovieClip {
suppose I have the following source table (called S): name gender code Bob 0
I just realized that I lack the fundamental knowledge of what exactly happens as

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.