美文网首页
iOS dispatch_sync

iOS dispatch_sync

作者: KnowWhy | 来源:发表于2018-09-12 15:12 被阅读0次

    dispatch_sync

    Submits a block object for execution on a dispatch queue and waits until that block completes.
    提交块对象以在调度队列上执行,并等待该块完成。
    
    Declaration
    void dispatch_sync(dispatch_queue_t queue, dispatch_block_t block);
    
    Parameters
    • queue
    The queue on which to submit the block. This parameter cannot be NULL.
    提交块的队列。 
    此参数不能为NULL。
    
    • block
    The block to be invoked on the target dispatch queue. This parameter cannot be NULL.
    要在目标调度队列上调用的块。 
    此参数不能为NULL。
    
    Discussion
    Submits a block to a dispatch queue for synchronous execution. Unlike dispatch_async, this function does not return until the block has finished. Calling this function and targeting the current queue results in deadlock.
    将块提交到调度队列以进行同步执行。 与dispatch_async不同,此功能在块完成之前不会返回。 调用此函数并以当前队列为目标队列会导致死锁。
    
    Unlike with dispatch_async, no retain is performed on the target queue. Because calls to this function are synchronous, it "borrows" the reference of the caller. Moreover, no Block_copy is performed on the block.
    与dispatch_async不同,不对目标队列执行持有。 因为调用此函数是同步的,所以它“借用”调用者的引用。 此外,不对块执行Block_copy。
    
    As an optimization, this function invokes the block on the current thread when possible.
    作为优化,可能的话此函数会在当前线程上调用块.
    

    相关文章

      网友评论

          本文标题:iOS dispatch_sync

          本文链接:https://www.haomeiwen.com/subject/phgvgftx.html