Task_EnqueueJob

What exactly is the meaning of the Task_EnqueueJob flag?

I see it being used only for async let tasks, but not for other kinds of tasks.

Why does it retain the task? How do other tasks get enqueued without this flag?

There's some situations where we create a task, but then manually convert it into a job and enqueue somewhere -- then this flag is false. Task.sleep is one such example.

TaskGroup tasks also just use the enqueue = true flag, we kick off the tasks as we create them.

It's also set to false in the "task to thread" mode where we run the tasks inline immediately, rather than spawning them off, here's how those places look like:

#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
    let flags = taskCreateFlags(
      priority: priority, isChildTask: true, copyTaskLocals: false,
      inheritContext: false, enqueueJob: false,
      addPendingGroupTaskUnconditionally: true,
      isDiscardingTask: false
    )

I missed the Swift code, I was searching only in C++ codebase. Thanks, now it makes sense!

1 Like