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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:43:52+00:00 2026-05-15T17:43:52+00:00

I am using a multi-threaded producer/consumer queue with a single (very fast) producer and

  • 0

I am using a multi-threaded producer/consumer queue with a single (very fast) producer and many, much slower, consumers. Each consumer has exclusive access to a piece of physical hardware, such as a phone line. The producer runs on the main thread and each consumer runs on its own thread. Each consumer thread is created and initialized when the program starts up.

What I am attempting to do is always use the first consumer if available, if it is busy then use the second consumer. If the first two are busy then use the third and so on. If consumer two is busy and consumer one is now ready, then it should use the first.

Simply locking the queue and using monitor.pulse when an item is en-queued in the producer and monitor.wait in the consumer (with the wait condition being the queue is empty) does not work since each consumer enters the wait queue at the mercy of the thread scheduler. This results in each consumer being used in a round-robin fashion.

Is there an easy way to pull this off?

EDIT:

Just implemented this by creating a list of hardware-bound objects that the consumer threads lock, waiting if there are none available, then passing the work item to the acquired device. Once the consumer is finished with the device, it sets it as available and pulses a waiting thread (if any).

  • 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-15T17:43:53+00:00Added an answer on May 15, 2026 at 5:43 pm

    It is a bit hard to see what would be wrong with round-robin. Assumption: what you really want to do is re-use the same hardware device as soon as it is available. So make that work, let each consumer thread negotiate what device to use. Should be simple with a List<bool> protected by a lock to indicate which device is available.

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

Sidebar

Related Questions

I'm wondering if anyone has any experience using log4net in a multi-threaded environment like
I'm tinkering away on a multithreaded downloader, using a producer/consumer queue construct; the downloading
i'm working with a multi-threaded program (using pthreads) that currently create a background thread
I have a multi-threaded application that is using pthreads. I have a mutex() lock
I am working on a multi-threaded application. This application started out as a single
I have a multi-threaded application build in C# using VS2010 Professional. It's quite a
I really have a strange situation. I'm making a Linux multi-threaded C application using
I am using a multi-dimensional dynamic array in delphi and am trying to figure
A legacy embedded system is implemented using a cooperative multi-tasking scheduler. The system essentially
I'm playing around with LinqToSQL using an existing multi-lingual database, but I'm running into

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.