Skip to content

Concurrency: Guard TG state with a mutex even with cooperative executor #75008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion stdlib/public/Concurrency/TaskGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,12 @@ class TaskGroupBase : public TaskGroupTaskStatusRecord {
};

protected:
#if SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY || SWIFT_CONCURRENCY_TASK_TO_THREAD_MODEL
// Guard with SWIFT_THREADING_NONE and not just SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY
// because the latter just means that the global executor is cooperative,
// but it doesn't mean that the target platform is always single-threaded. For example, on
// wasm32-unknown-wasip1-threads, the global executor is cooperative, but users can still set up their
// own TaskExecutor with multiple threads.
#if SWIFT_THREADING_NONE || SWIFT_CONCURRENCY_TASK_TO_THREAD_MODEL
// Synchronization is simple here. In a single threaded mode, all swift tasks
// run on a single thread so no coordination is needed. In a task-to-thread
// model, only the parent task which created the task group can
Expand Down