A queue that prevents completion

Mark Yourself Question

  1. Grab a piece of paper and try this problem yourself.
  2. When you're done, check the "I have answered this question" box below.
  3. View the solution and report whether you got it right or wrong.

A worker sends exactly two simulation results through an initially empty, thread-safe queue that can hold one result. Putting a result into a full queue waits until space becomes available. Getting a result from an empty queue waits until a result becomes available.


The worker puts the first result, puts the second result, and then finishes. The coordinator first joins the worker, meaning it waits for the worker to finish, and only afterward gets the two results. There are no other consumers, timeouts, or failures.


Two lanes show a worker sending two results before finishing and a coordinator joining before receiving both results.


a) Determine whether both activities can finish. Explain the waiting dependencies.


b) Keep the queue capacity at one and propose a coordinator operation order that allows both activities to finish, assuming each runnable activity eventually receives processor time.


c) Explain whether adding an application mutex around each queue operation would repair the original order.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Threads and Concurrency Questions: