zoukankan      html  css  js  c++  java
  • iOS多线程中的单例

     1 #import "MyHandle.h"
     2 
     3 static MyHandle *handle = nil;
     4 @implementation MyHandle
     5 // 传统写法
     6 // 此时如果多个任务并发执行,他就不会满足单例的优点
     7 //+ (MyHandle *)shareMyHandle {
     8 //    if (nil == handle) {
     9 //        handle = [[MyHandle alloc] init];
    10 //    }
    11 //    return handle;
    12 //}
    13 
    14 // 多线程中的写法
    15 + (MyHandle *)shareMyHandle {
    16     // 在GCD 中保证只执行一次, 用于记录内容是否执行过
    17     static dispatch_once_t onceToken;
    18     dispatch_once(&onceToken, ^{
    19         handle = [[MyHandle alloc] init];
    20     });
    21     return handle;
    22 }
    23 
    24 @end
  • 相关阅读:
    模型
    smarty变量
    smarty变量调节器
    分页
    表单验证(注册)
    php数据库访问
    php面向对象 继承
    php 面向对象
    php正则数组
    php 函数
  • 原文地址:https://www.cnblogs.com/crazygeek/p/5537613.html
Copyright © 2011-2022 走看看