Skip to content

Commit c8a3e75

Browse files
Concurrency: Guard TG state with a mutex even with cooperative executor
`SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY` 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. This patch guards the `TaskGroup` state with a mutex even with a cooperative executor by respecting threading package instead. This change effectively affects only wasm32-unknown-wasip1-threads.
1 parent e259c7b commit c8a3e75

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

stdlib/public/Concurrency/TaskGroup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class TaskGroupBase : public TaskGroupTaskStatusRecord {
292292
};
293293

294294
protected:
295-
#if SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY || SWIFT_CONCURRENCY_TASK_TO_THREAD_MODEL
295+
#if SWIFT_THREADING_NONE || SWIFT_CONCURRENCY_TASK_TO_THREAD_MODEL
296296
// Synchronization is simple here. In a single threaded mode, all swift tasks
297297
// run on a single thread so no coordination is needed. In a task-to-thread
298298
// model, only the parent task which created the task group can

0 commit comments

Comments
 (0)