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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:03:18+00:00 2026-06-06T17:03:18+00:00

I need for a queue which can be accessed simultaneously by 2 threads, one

  • 0

I need for a queue which can be accessed simultaneously by 2 threads, one can be enqueueing an item while a different one is dequeueing another item. Does the Queue<T> class meet this requirement? Or should I implement it from scratch (for example using a single producer/consumer circular queue implementation like this)?

  • 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-06T17:03:19+00:00Added an answer on June 6, 2026 at 5:03 pm

    If you’re using .NET 4.0 you can use ConcurrentQueue. This is the recommended method.

    Regarding Queue<T> itself, the MSDN page says the following (scroll down to the Thread Safety section:

    A Queue can support multiple readers concurrently, as long as the collection is not modified. Even so, enumerating through a collection is intrinsically not a thread-safe procedure. To guarantee thread safety during enumeration, you can lock the collection during the entire enumeration. To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.

    Besides these solutions, you can implement your own thread safe queue. One way to achieve thread safety is immutability (though this will involve some locking). You can read about writing an immutable queue in Eric Lippert’s blog, here. Alternatively, you can make use of the F#-based data types, most of which are immutable.

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

Sidebar

Related Questions

I have a queue in which I can enqueue different threads, so I can
I need a queue which multiple threads can put stuff into, and multiple threads
I need to create a service which can process queued requests on a configured
I'm implementing a interpreter-like project for which I need a strange little scheduling queue.
I need a priority queue where I can increase or decrease the priority key.
I need to create a queue in matlab that holds structs which are very
I have a very complex system (100+ threads) which need to send email without
I have been using NSURLConnection's sendAsynchronousRequest:queue:completionHandler: method which is great. But, I now need
Say I have a queue full of tasks which I need to submit to
Is there a command which can tell me whats in the Solaris run queue?

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.