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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:03:05+00:00 2026-05-26T22:03:05+00:00

So, I am using C on a unix system and have access to the

  • 0

So, I am using C on a unix system and have access to the pthreads & semaphore.h libraries.

Here is the problem (I believe this boils down to a “writer priority rw lock” problem):

For simplicities sake, I have two different processes that a thread can run: A & B.

B is more important than A, and thus if there is ever a B waiting to run, I do not want any more A processes to start executing until all of the B processes have run. Additionally, while multiple A processes can run concurrently, only 1 B process can execute at a time.

The current way I am doing this (which I believe to either be wrong, inefficient, or both) is to have the B processes require a lock for their entire execution time and the A processes will acquire and immediately release the lock at the beginning of their execution. I am also using semaphores here to allow for the multi-reader/single writer functionality.

For various reasons, the pthread_rwlock functionality is not usable on this system, so the solution can’t involve them.

  • 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-26T22:03:05+00:00Added an answer on May 26, 2026 at 10:03 pm

    If A is going to immediately release the lock, but continue using whatever resource it is that you want to lock, then why do you even bother locking to begin with?

    You said:
    -Multiple A’s can run simultaneously
    -Only one B can run at a time

    I’m assuming (but correct me if I’m wrong):
    -B and A cannot run at the same time

    If you immediately release the lock from A then that’s going to allow a B to run at the same time. Am I missing anything here?

    The solution:

    Have a mechanism that gets the resource for the a threads. That mechanism only puts a lock on the resource one time when the first A thread starts and releases it only when all A threads are gone.

    Have a cancel token for the A threads to use that gets set to true when a B thread begins, then when all A threads have exited the B thread can begin.

    The B thread obviously locks and doesn’t release until it’s completed.

    Don’t forget to check the cancel token frequently enough in the A thread so that it doesn’t take too long to exit when asked.

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

Sidebar

Related Questions

I have this command that is using a unix pipe system(curl . escapeshellarg($flv['dl']) .
This is installed on a Unix system I don't have direct access to, but
I have a site which I want to download using Unix wget . If
I am using Vim for windows installed in Unix mode. Thanks to this site
I have created a text file in Unix environment using Java code. For writing
I guess this question is directed at Linux/Unix system programming experts (unfortunately I am
I am connecting to remote Unix system using putty and .ppk key file. Now
On a Unix systems it's very easy to compile the CLASSPATH by using find:
Using UNIX socket APIs on Linux, is there any way to guarantee that I
Using the unix dig command, I can get the following MX record: $ dig

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.