The use of dispatch_group and dispatch_barrier

I was asked to make use of GCD depends on the usage of the complete answer to come up, down after the search of the advanced usage of the GCD, found himself for the mastery of GCD is still very shallow, like dispatch_group and dispatch_barrier don’t know.
dispatch_group is used to solve dependency problems, or to solve sequential execution problems of concurrent sequences. There are several main ways:

Dispatch_group_t dispatch_group_create (void); void dispatch_group_enter (dispatch_group_t group); void dispatch_group_leave (dispatch_group_t group); long dispatch_group_wait (dispatch_group_t group, dispatch_time_t timeout); void dispatch_group_notify (dispatch_group_t group, dispatch_queue_t queue, dispatch_block_t block);

It is important to note that you should enter group first and then call notify, otherwise it might cause a direct call to the notify callback.

Dispatch_barrier is mainly used for the lock, it is mainly used for concurrent read and write requirements, the normal use of dispatch_sync (dispatch_async) to perform a read operation, the write operation is carried out using the dispatch_barrier_sync (dispatch_barrier_async), is equal to the write operation to add the mutex, can avoid multiple threads to perform write operations. This enables concurrent read operations and mutually exclusive write operations, which improves access performance compared to all add – exclusive locks.