zoukankan      html  css  js  c++  java
  • gcd

    @property (nonatomic) dispatch_semaphore_t semaphore;

     self.semaphore = dispatch_semaphore_create([self.progressViews count]);

    dispatch_semaphore_wait(self.semaphore, DISPATCH_TIME_FOREVER);

    dispatch_semaphore_signal(self.semaphore);

    ===================================================

    dispatch_source_t  source = dispatch_source_create(DISPATCH_SOURCE_TYPE_DATA_ADD/OR,  0, 0, dispatch_get_main_queue());

     __block long totalComplete = 0;

       dispatch_source_set_event_handler(source, ^{

         long value = dispatch_source_get_data(source);

         totalComplete += value;

         self.progressView.progress = (CGFloat) totalComplete /100.0f;

       });

    dispatch_resume(source);

     dispatch_queue_t

         queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,

    0);

         dispatch_async(queue, ^{

           for (int i = 0; i <= 100; ++i) {

             dispatch_source_merge_data(source, 1);

             usleep(20000);

           }

    });

    =======

    static char kMyKey;

       CFStringRef *value = CFStringCreate...;

       dispatch_queue_set_specific(queue,&kMyKey,(void*)value,(dispatch_function_t)CFRelease);

       dispatch_sync(queue, ^{

         CFStringRef *string = dispatch_get_specific(&kMyKey);

         ...

    });

    ========

    dispatch_queue_set_specific(q, &sQueueTagKey, (__bridge void*)q, NULL);

    =============

    Dispatch Data and Dispatch I/O

    dispatch_io_t serverChannel = dispatch_io_create(DISPATCH_IO_STREAM, socket, queue,

                                            ^(int error) {

                                              NSAssert(!error,

                                                     @"Failed socket:%d", error);

                                              NSLog(@"Closing connection");

                                              close(socket);

    });

     dispatch_data_create

    NSString *writePath = [self outputFilePathForPath:path];

         dispatch_io_t

         fileChannel = dispatch_io_create_with_path(DISPATCH_IO_STREAM,

                                                    [writePath UTF8String],

                                                    O_WRONLY|O_CREAT|O_TRUNC,

                                                    S_IRWXU,

                                                    queue,

    nil);

    dispatch_io_write(serverChannel, 0, requestData, queue,

           ^(bool serverWriteDone,

             dispatch_data_t serverWriteData,

             int serverWriteError) {

             NSAssert(!serverWriteError,

                      @"Server write error:%d", serverWriteError);

             if (serverWriteDone) {

               [self readFromChannel:serverChannel

    } });

  • 相关阅读:
    django页面分类和继承
    django前端从数据库获取请求参数
    pycharm配置django工程
    django 应用各个py文件代码
    CF. 1428G2. Lucky Numbers(背包DP 二进制优化 贪心)
    HDU. 6566. The Hanged Man(树形背包DP DFS序 重链剖分)
    小米邀请赛 决赛. B. Rikka with Maximum Segment Sum(分治 决策单调性)
    区间树 学习笔记
    CF GYM. 102861M. Machine Gun(主席树)
    2016-2017 ACM-ICPC East Central North America Regional Contest (ECNA 2016) (B, D, G, H)
  • 原文地址:https://www.cnblogs.com/anjsxz/p/3772659.html
Copyright © 2011-2022 走看看