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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:45:11+00:00 2026-05-18T10:45:11+00:00

Is there a way for, with unix semaphores, set their values? I’m in need

  • 0

Is there a way for, with unix semaphores, set their values? I’m in need of always calling post() from multiple consumers and once in a while call a wait() that’ll wait until the next post() happens.

How can this be achieved?

The reason for this is that I am implementing the Producer / Consumer problem (1 producer / up to 2 consumers). Each consumer has an internal queue where it stores items that it seems can’t be put on the output yet as there are still other packets missing from others consumers so that they are all output in the correct order(as they came from the producer). When any of the queues is considered full (let’s say, with 10 items), I’d want that process to wait until the other process finishes its work (as there are only 2 processes, I have the guarantee that the packet that other process is yielding is the packet I need to start doing some output!).

My idea is that each time a consumer processes anything and looks up to put it in the output, it should make a call on something like post() on a semaphore. Every time a consumer has its queue full, it should do a kind of wait() on that same semaphore. This way, when the other consumer finishes its work, this one is waked up.

How should solve this situation? Am I on the right path? I am limited to using semaphores and shared memory, in this project.

Of course, the idea is to avoid as much as possible spinning.

Thanks

  • 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-18T10:45:11+00:00Added an answer on May 18, 2026 at 10:45 am

    It seems that you mostly need a barrier to synchronize your consumers.
    It seems that Posix gives an implementation of it (pthread_barrier_*).

    So create your shared barrier with the number of consumers; when a consumer finishes, it must “wait at the barrier”.

    Otherwise, you can implement it with another semaphore.

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

Sidebar

Related Questions

is there a way to convert from unix timestamp to GMT in mysql while
Is there a way to use unix date to print the number of seconds
Is there a way to get the instruction pointer of a running application Unix?
Using UNIX socket APIs on Linux, is there any way to guarantee that I
I am a newbie to unix. I am wondering if there is any way
Is there way to get file from windows xp command prompt? I tried to
is there way how to get name ov event from Lambda expression like with
Is there any way to obtain Unix Time with nanoseconds with strftime in bash?
Is there a painless way to convert unix timestamps, MySQL timestamps, MySQL datetimes (or
Is there an easy way to see whether particular file has DOS/MAC/UNIX line endings?

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.