Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do detached and assignCurrentContext meaning?

Tags:

swift

When I add a job into the queue, DispatchWorkItemFlags gives us several options to choose

public func sync<T>(flags: DispatchWorkItemFlags, execute work: () throws -> T) rethrows -> T
public static let barrier: DispatchWorkItemFlags
public static let detached: DispatchWorkItemFlags
public static let assignCurrentContext: DispatchWorkItemFlags

I know barrier makes the job not being executed the same time with others, but I don't know what detached and assignCurrentContext are, and Apple don't provide any description about them, so who can tell me about this.

like image 210
Laughing Avatar asked Jan 22 '26 00:01

Laughing


1 Answers

You can read about them in the dispatch_block_flags_t manual:

DISPATCH_BLOCK_ASSIGN_CURRENT Indicates that a dispatch block should be assigned the execution context attributes that are current at the time the block object is created. …

DISPATCH_BLOCK_BARRIER Indicates that a dispatch block should act as a barrier block when submitted to a DISPATCH_QUEUE_CONCURRENT queue. …

DISPATCH_BLOCK_DETACHED Indicates that a dispatch block should execute disassociated from current execution context attributes such as QoS class, os_activity_t, and properties of the current IPC request, if any. …

I’ve only copied the first sentence from each flag’s documentation. Click the link for more details.

like image 73
rob mayoff Avatar answered Jan 25 '26 03:01

rob mayoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!