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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:54:11+00:00 2026-06-14T08:54:11+00:00

I want to know how to solve the producer/consumer problem but using 2 differents

  • 0

I want to know how to solve the producer/consumer problem but using 2 differents consumers and I also need to know how to solve it using strict alternation.

I made the following algorithm for 1 producer and 1 consumer

producer()
{
   while(true)
   {
       if i == N //full buffer
          turn = 1
       while turn <> 0
       {
           // nothing
       }
       produceitem(&item)//produce the item
       insertitem(item, buffer)//insert the item in the buffer
       turn = 1
       //process zone
   }
}

consumer()
{
   while(true)
   {
       if i == 0 //empty buffer
          turn = 0
       while turn <> 1
       {
           // nothing
       }
       consumeitem(&item)
       deleteitem(buffer)//erase the item from buffer
       turn = 0
       //process zone
   }
}

Using that kind of “pseudo-code” I want to know to to solve the same problem(if the last was OK) with 2 consumers.

  • 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-14T08:54:12+00:00Added an answer on June 14, 2026 at 8:54 am

    You can use the router pattern on small scale in both cases:

    Router
    (source: enterpriseintegrationpatterns.com)

    Basically after the queue you place special artifical consumer (router, just one). If you have two competing consumers, just put each received message randomly either in outQueue1 or outQueue2.

    In case of strict alternation, the router remember which queue was used last time and sends to the second one.

    If you don’t want to introduce extra step, you need some sort of synchronization. In first case both consumers are competing for the same lock that they obtain randomly. The latter case is more complicated and will require more advanced synchronization so that both consumers are woken up alternatively.

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

Sidebar

Related Questions

I got this problem somewhere, and I want to know how to solve this
want to know why String behaves like value type while using ==. String s1
I'm trying to use STL to solve the following problem (I don't want to
This was at a community college. I failed it, but want to know the
I have a problem. I need to know whether my page has global errors
I want to know what I would need to type into the formula box
I want to know which is best strategy to aboard the following problem in
i want know how i can manage multiple twitter account on iOS in my
i want know if is possible, to get a specific element value of a
please help me. I want know about what types of flags to run an

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.