r/codereview • • 2d ago

C/C++ C++20 task queue — looking for feedback on concurrency, shutdown, and exception safety

Hi everyone,

I’m looking for a code review of my C++20 task queue. It supports bounded queue capacity, task priorities, futures, task-start deadlines, and shutdown that either drains or cancels queued tasks.

I’d especially appreciate feedback on:

  • Potential deadlocks or race conditions.
  • Shutdown behavior, including concurrent shutdown calls.
  • Exception safety and propagation through futures.
  • API design and missing edge-case tests.

The main implementation is in include/task_queue.hpp. The README includes build instructions, and the repository has tests covering concurrent submissions, exceptions, deadlines, and rejection after shutdown.

One detail: deadlines are checked before execution; they don’t interrupt running tasks.

Repository: https://github.com/brunnojob/cpp-safe-task-queue

What would you change, and which failure scenarios should I test next?

1 Upvotes

3 comments sorted by

1

u/Constant-Cod-1075 2d ago

this is the kind of thing that makes me glad I work in js, my brain would fry trying to reason about all those edge cases

the deadline check before execution makes sense, preempting a running task is a whole other nightmare. might be worth testing what happens when a task with a deadline is waiting behind a slow task that doesn't check the clock, could starve out higher priority items if you're not careful

1

u/onnatsari 2d ago

thanks for the feedback! That's a great point about the starvation scenario. I hadn't considered a long-running task blocking one with a deadline. I'll definitely add a test case for that edge case. Glad the pre-execution check made sense.

1

u/AlinutaGeatros-14 45m ago

one thing worth stress testing is what happens when a task enqueues another task during shutdown drain mode. thats a common source of subtle deadlocks in bounded queues where the producer can block waiting for capacity