zoukankan      html  css  js  c++  java
  • ios多线程之NSThread头文件详解

    1、NSThread
    头文件中的相关方法
    //获取当前线程
     +(NSThread *)currentThread; 
    //创建线程后自动启动线程
    + (void)detachNewThreadSelector:(SEL)selector toTarget:(id)target withObject:(id)argument;
    //是否是多线程
    + (BOOL)isMultiThreaded;
    //线程字典
    - (NSMutableDictionary *)threadDictionary;
    //线程休眠到什么时间
    + (void)sleepUntilDate:(NSDate *)date;
    //线程休眠多久
    + (void)sleepForTimeInterval:(NSTimeInterval)ti;
    //退出线程
    + (void)exit;
    
    //线程优先级
    + (double)threadPriority;
    + (BOOL)setThreadPriority:(double)p;
    
    - (double)threadPriority NS_AVAILABLE(10_6, 4_0);
    - (void)setThreadPriority:(double)p NS_AVAILABLE(10_6, 4_0);
    
    //调用栈返回地址
    + (NSArray *)callStackReturnAddresses NS_AVAILABLE(10_5, 2_0);
    + (NSArray *)callStackSymbols NS_AVAILABLE(10_6, 4_0);
    
    //设置线程名字
    - (void)setName:(NSString *)n NS_AVAILABLE(10_5, 2_0);
    - (NSString *)name NS_AVAILABLE(10_5, 2_0);
    
    //获取栈的大小
    - (NSUInteger)stackSize NS_AVAILABLE(10_5, 2_0);
    - (void)setStackSize:(NSUInteger)s NS_AVAILABLE(10_5, 2_0);
    
    //是否是主线程
    - (BOOL)isMainThread NS_AVAILABLE(10_5, 2_0);
    + (BOOL)isMainThread NS_AVAILABLE(10_5, 2_0); // reports whether current thread is main
    + (NSThread *)mainThread NS_AVAILABLE(10_5, 2_0);
    
    - (id)init NS_AVAILABLE(10_5, 2_0);	// designated initializer
    - (id)initWithTarget:(id)target selector:(SEL)selector object:(id)argument NS_AVAILABLE(10_5, 2_0);
    
    //是否正在执行
    - (BOOL)isExecuting NS_AVAILABLE(10_5, 2_0);
    //是否执行完成
    - (BOOL)isFinished NS_AVAILABLE(10_5, 2_0);
    
    //是否取消线程
    - (BOOL)isCancelled NS_AVAILABLE(10_5, 2_0);
    - (void)cancel NS_AVAILABLE(10_5, 2_0);
    
    //线程启动
    - (void)start NS_AVAILABLE(10_5, 2_0);
    
    - (void)main NS_AVAILABLE(10_5, 2_0);	// thread body method
    
    @end
    
    //多线程通知
    FOUNDATION_EXPORT NSString * const NSWillBecomeMultiThreadedNotification;
    FOUNDATION_EXPORT NSString * const NSDidBecomeSingleThreadedNotification;
    FOUNDATION_EXPORT NSString * const NSThreadWillExitNotification;
    
    @interface NSObject (NSThreadPerformAdditions)
    
    //与主线程通信
    - (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait modes:(NSArray *)array;
    - (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait;
    	// equivalent to the first method with kCFRunLoopCommonModes
    
    //与其他子线程通信
    - (void)performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(id)arg waitUntilDone:(BOOL)wait modes:(NSArray *)array NS_AVAILABLE(10_5, 2_0);
    - (void)performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(id)arg waitUntilDone:(BOOL)wait NS_AVAILABLE(10_5, 2_0);
    	// equivalent to the first method with kCFRunLoopCommonModes
    
    
    //隐式创建并启动线程
    - (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg NS_AVAILABLE(10_5, 2_0);
    
     
  • 相关阅读:
    Ozon Tech Challenge 2020 (Div.1 + Div.2, Rated, T-shirts + prizes!)D(交互,DFS)
    【PAT甲级】1122 Hamiltonian Cycle (25分)
    Codeforces Round #622 (Div. 2)D(离散化,状压DP)
    Codeforces Round #625 (Div. 1, based on Technocup 2020 Final Round)B(反向建图,BFS最短路)
    Codeforces Round #625 (Div. 1, based on Technocup 2020 Final Round)C(线段树,扫描线)
    【PAT甲级】1121 Damn Single (25分)
    【PAT甲级】1120 Friend Numbers (20分)(SET遍历)
    【PAT甲级】1119 Pre- and Post-order Traversals (30分)(已知先序后序输出是否二叉树唯一并输出中序遍历)
    【PAT甲级】1118 Birds in Forest (25分)(并查集)
    LOJ2181 排序
  • 原文地址:https://www.cnblogs.com/ndyBlog/p/3958895.html
Copyright © 2011-2022 走看看