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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:14:23+00:00 2026-05-11T19:14:23+00:00

Let’s say I have two buffers. Producer fills buffer #1, then fills buffer #2.

  • 0

Let’s say I have two buffers. Producer fills buffer #1, then fills
buffer #2. The consumer consumes one buffer a time, and it’s very
slow. While it is consuming buffer #1, the producer is ready to fill
another buffer, but they are all full, and the consumer hasn’t
finished yet with #1. So, the producer waits.

Instead of waiting, I want the producer to update the “free” buffer.
That is, while the consumer is consuming buffer #1, the producer
should write new data on buffer #2 as soon as it has it ready (the
“old” data is overwritten and lost). If the consumer hasn’t finished
yet with #1, and the producer has more data to write, it should write
again on #2, and so on.
When the consumer finally consumes all the data in #1, it should
immediately start to consume the freshly-written data in buffer #2,
and the producer should keep on updating #1.

(imagine the producer is acquiring video frames in realtime at high speed, while the consumer is slowly elaborating them; the consumer doesn’t mind if it skips some
frame, but it must always process the last frame acquired. The
producer, instead, cannot slow down nor wait, because it must acquire
every frame).

Is there a way to do this kind of thing with semaphores? Is it a well-
known concurrency problem? And, in case, is it possible to extend
this problem to n > 2 buffers?

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-11T19:14:24+00:00Added an answer on May 11, 2026 at 7:14 pm

    Well, you could just have a buffer(queue) of buffers. Some type of synchronized queue structure to determine which buffers are being used. This would work for n >= 2 buffers.

    I guess it would work like this: Producer starts writing to buffer 1, but doesn’t remove it from the queue. Consumer starts consuming from buffer 1, and removes it from the queue. Once buffer 1 is full, the producer checks the queue to see which buffers are available, and it sees only buffer 2 is available. The producer starts writing to buffer 2. When buffer 2 is full, it will check the queue again and see that buffer 2 is still available, so it will write to it again. Once the consumer is done with buffer 1, it will remove buffer 2 from the queue and place buffer 1 back. Once the producer is done with 2, it will see only buffer 1 is available and start writing to it. I hope this is what you were describing. (I don’t like dealing with just semaphores, I prefer to use higher data structures, eg. queues).

    To deal with multiple producers, introduce another queue to determine which buffers are being used by a producer. So now you will have a producer queue and a consumer queue, and I think that handles all your situations.

    • 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 a C++ Visual Studio 2010 solution with 2 projects: one
Let's say I have two tables orgs and states orgs is (o_ID, state_abbr) and
Let's say I have two objects, Master and Slave . Slave has a method
Let's say I have the following two lists of tuples myList = [(1, 7),
Let's say I have 2 windows in my application, and two classes responsible for
Let say I have two UIViews: View1: - bounds: 0, 0, 20, 20 -
Let's say I have two assemblies: BusinessLogic and Web. BusinessLogic has an application setting
Let's say I don't have photoshop, but I want to make pattern files (.pat)
Let's say I have a method in java, which looks up a user in
Let me explain best with an example. Say you have node class that can

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.