Can you spot the deadlock 4 ?!


Hello everyone,

welcome back to can you spot the deadlock take 4. As a reminder, this a puzzle in a form of multithreaded code. You have to identify the issue that hides in it, usually a deadlock, but not always. Please post your answer in the comments section.

Since it has been a long time since the last episode, let’s start easy!

So what is the problem with this code and how would you fix it?

class Program
{
  static void Main(string[] args)
  {
    var workerThread = new Thread(Worker);
    workerThread.Start();
    workerThread.Join();
  }

  static void Worker()
  {
    while (Thread.CurrentThread.IsAlive)
    {
      Console.Write("Blah ");
    }
  }
}

7 thoughts on “Can you spot the deadlock 4 ?!

  1. Too easy 🙂
    IsAlive property is set to true when thread ends. In this case the thread will continue to run in background. Therefore the thread loop will never exit without an exception.

    Like

  2. Too easy 😀
    Thread property IsAlive is set to false only when the thread ends.
    Or in this case thread doesn’t ends with main function and is still running in background.
    the domain will not be unloaded without an exception.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.