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

  • Home
  • SEARCH
  • 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 8707109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:47:09+00:00 2026-06-13T03:47:09+00:00

This pseudocode run concurrently in multiple threads causes deadlock: Resource res1 = pool.get(); …

  • 0

This pseudocode run concurrently in multiple threads causes deadlock:

Resource res1 = pool.get();
...
Resource res2 = pool.get();
...
pool.release(res2);
pool.release(res1);

Is that an expected behavior? (I guess it is)

Deadlock doesn’t seem to happen if the size of pool is twice of the number of threads – is this statement correct?

Is there a “scientific” name for this kind of deadlock in computer science? Would appreciate some links.

Thanks

  • 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-13T03:47:11+00:00Added an answer on June 13, 2026 at 3:47 am

    Suppose you have two threads and two resources.

    Thread A executes res1 = pool.get() and acquires one resource. Thread B executes res1 = pool.get() and acquires one resource. Now the pool is exhausted, so neither thread can finish res2 = pool.get().

    The problem goes away if you have one spare resource (i.e. at least n+1 resources for n threads), since in that case one thread is guaranteed to get two resources, finish, and thus release enough resources for the other threads to use. Increasing the number of resources improves parallelism; with twice as many resources as threads, every thread can get resources without blocking and thus all threads can execute in parallel.

    AFAIK this is simply known as “deadlock” since it’s essentially a textbook example of the phenomena. Both tasks are now waiting on each other to release the necessary resource.

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

Sidebar

Related Questions

I have some code that does something like this pseudocode: Use CURL to get
I have code that I'd like to run that looks something like this pseudocode:
I have this (pseudocode): var a = Math.random(); // returns random number from 0
I noticed with activemq (5.5) if I do this pseudocode: connection = new ActiveMQConnectionFactory(...)
This is for a red black tree. For the pseudocode p[z] <-- y, would
Is there any reason why this shouldn't work? [PseudoCode] main() { for (int i
How can we run a Java or C# program without JIT help? pseudocode: for(int
Have a look at this pseudocode: string exe_path = system.get_exe_path() print This executable is
How do i run max n threads in a c# code block? I'll like
I got a fixed number of threads. I want each thread to run three

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.