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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:10:08+00:00 2026-06-05T10:10:08+00:00

I have a synchronized queue that provides a condition variable. That condition variable signals

  • 0

I have a synchronized queue that provides a condition variable.

That condition variable signals when data is added to the queue.

I have 5 threads:

Thread.new do
  loop do
    @queue.synchronize {
      cond.wait_until { @queue.has_data? || @queue.finished? }
    }
    # some processing code that can also call @queue.enqueue
  end
end

Then I do:

@queue.enqueue some_data
@threads.each(&:join)

MyQueue#enqueue looks like this:

def enqueue(data)
  synchronize do
    @pending << v unless queued?(data) || processed?(data) || processing?(data)
    data_cond.signal
  end
end

def finished?
  @started && @processing.empty? && @pending.empty?
end

def has_data?
  !@pending.empty?
end

And I get on #join

deadlock detected

How exactly does this cause a deadlock and how would one fix it?

  • 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-05T10:10:10+00:00Added an answer on June 5, 2026 at 10:10 am

    I wonder if this is a problem that all of the threads are blocked on the same condition variable, and there isnt a thread available to enqueue data, which would release the other threads.

    Based on the comment in this code:

    Thread.new do
      loop do
        @queue.synchronize {
          cond.wait_until { @queue.has_data? || @queue.finished? }
        }
        # some processing code that can also call @queue.enqueue
      end
    end
    

    Your comment that mentions “some processing code that can also call @queue.enqueue”, is this the only place where @queue.enqueue is called? If so, then all of the threads will be blocked on the condition variable and none will be able to get to the point to be able to call enqueue. Im sure Ruby can detect that all threads are locked on the same entity and none are available to release it, thus deadlock.

    If you do indeed have a separate thread that only enqueues (which would be a typical producer/consumer situation) make sure that it doesnt also wait on the condition variable, which could also cause deadlock.

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

Sidebar

Related Questions

I have a program with several worker threads, and a main thread that receives
I'm working a program that will have a bunch of threads processing data. Each
I have a Queue object that I need to ensure is thread-safe. Would it
I'm putting together a custom SynchronizedCollection<T> class so that I can have a synchronized
I have a problem where I need to synchronize processing for multiple threads across
I am trying to implement a synchronized queue with condition variables using the boost
I have two threads, one that dispatches messages and another that parses them. Simple,
i have a server at the moment which makes a new thread for every
I have created a synchronized queue and am using SyncLock on the SyncRoot property
I need a system that writes sequentially, very fast to a synchronized persistent 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.