多线程 NSThread

来源:互联网 发布:淘宝改版中国质造 编辑:程序博客网 时间:2024/06/11 09:57
对于NSThread线程类,其方法

+ (void)detachNewThreadSelector:(SEL)aSelector toTarget:(id)aTarget withObject:(id)anArgument
Parameters
aSelector

The selector for the message to send to the target. This selector must take only one argument and must not have a return value.

This selector 只能带一个参数,并且This selector 线程入口方法没有返回值

aTarget

The object that will receive the message aSelector on the new thread.

anArgument

The single argument passed to the target. May be nil.

作为单一参数传递给target,也可以是nil;

Discussion

For non garbage-collected applications, the method aSelector is responsible for setting up an autorelease pool for the newly detached thread and freeing that pool before it exits. Garbage-collected applications do not need to create an autorelease pool.

如果应用程序没有垃圾回收机制,则aSelector必须为新开启的线程建立一个autorelease pool并且在线程推出前释放掉pool,有垃圾回收机制的应用程序则不需要创建autorelease pool。

The objects aTarget and anArgument are retained during the execution of the detached thread, then released. The detached thread is exited (using the exit class method) as soon as aTarget has completed executing theaSelector method.

在线程执行期间,aTarget和anArgument都将被retained,然后released掉。一旦aTarget执行完线程方法中的命令,这个线程就将使用类方法exit退出关闭;

If this thread is the first thread detached in the application, this method posts theNSWillBecomeMultiThreadedNotification with object nil to the default notification center.

如果这个线程是应用程序中首个被启用的线程,它将投递一个带nil参数的NSWillBecomeMultiThreadNotification通知到默认的通知中心。


原创粉丝点击