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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:08:30+00:00 2026-05-23T06:08:30+00:00

I have a multi thread application. One thread inserts in a queue and many

  • 0

I have a multi thread application.

One thread inserts in a queue and many thread reads form this queue. In order to read properly, reader threads lock the queue like the following code.

My question is: Does the inserter thread become blocked when the following code is called by reader threads since it uses the same queue? Or it continues inserting without interruption?

lock ( MsgQueue ) {
    if ( MsgQueue.Count == 0 ) {
         Monitor.Wait( MsgQueue );
         continue;
    }
    msg = MsgQueue.Dequeue( );
}
  • 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-23T06:08:31+00:00Added an answer on May 23, 2026 at 6:08 am

    The inserter thread is being blocked at points, yes.

        lock ( MsgQueue ) {
            if ( MsgQueue.Count == 0 ) {  // LINE 1
                Monitor.Wait( MsgQueue ); // LINE 2
                continue;
            }
            msg = MsgQueue.Dequeue( ); // LINE 3
        }
    

    At line 1 the lock is held by the reader, so the inserter is blocked.

    At line 2 the lock is released, and not reacquired until the inserter presumably calls Monintor.Pulse on MsgQueue.

    At line 3 the lock is still being held (from line 1), and afterwards it is released again due to exiting the lock scope.

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

Sidebar

Related Questions

Hi: I have a multi thread Java application. There are many temporary objects. -XX:MaxTenuringThreshold=1
see basically i have one multi-thread application in which i want to see the
I have a multi-threaded application written in Python in which one thread takes care
I have a multi threaded application which has one producer thread and several consumer
I have a multithread application. I want only one thread to execute my function
I have created an multi thread application on IIS (ASP.NET MVC), When the threading
I have an application which runs some multi-threading process. In each thread I'm sharing
I have a multi-threaded application with (4) thread i want to know how much
This is a multi threaded scenario. The main thread handles the application and UI
I have a 250Mb file to be read. And the application is multi threaded.

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.