NVIDIA / NVIDIA/stdexec

Provide a `tbb_sync_wait` that provides deadlock-safe reentrant calling.

Open
#1,429 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
2.4k
Forks
270
Avg merge
3d 6h
Merged PRs (30d)
39

Description

As I've discussed on a few other tickets, stdexec::sync_wait isn't safely reentrant in that stdexec::sync_wait(schedule(sch)) blocks the calling thread, and so can deadlock if it's the last free thread in sch. I don't have a general solution, but a specific solution is to implement a tbb_sync_wait that uses tbb::task_group g in place of stdexec::run_loop, where the delegation scheduler uses g.run(f). This allows the calling thread to potentially do all the work, only blocking while work is being done by a completely separate scheduler.

Here's a sketch of an implementation: https://godbolt.org/z/dWPzW86nG
That implementation lets you recursively call tbb_sync_wait as deeply nested as you like without deadlocking and parallelizes bulk using tbb::parallel_for.

Ideally we'd have a synchronously-cancelable scheduler which would allow us to get this sort of behavior more generally, letting more than one scheduler attack the same queue of work even in the case that one scheduler is completely occupied. But until then, this is the beast I can suggest. It

  1. Lets you call tbb_sync_wait without fear of deadlock.
  2. Lets simple parallel algorithms using bulk Just Work.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing stdexec::sync_wait, stdexec::run_loop, and the linked Godbolt implementation sketch, then examine how the delegation scheduler and tbb::task_group interact with nested calls. Done means providing a tbb_sync_wait that avoids deadlock during recursive scheduling and supports the described bulk parallelization behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
distributed-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.