Copyright ã1994 by NeXT Computer, Inc.  All Rights Reserved.

NSThread 

Inherits From:	NSObject

Conforms To:	NSObject (NSObject)

Declared In:	Foundation/NSThread.h 

Class Description

An NSThread object controls a thread of execution. You use an NSThread when you want to terminate or delay a thread or you want a new thread. 

A thread is an executable unit. A task is made up of one or more threads. Each thread has its own execution stack and is capable of independent I/O. All threads share the virtual memory address space and communication rights of their task. When a thread is started, it is detached from its initiating thread. The new thread runs independently. That is, the initiating thread does not know the new thread's state.

To obtain an NSThread object that represents your current thread of execution, use the currentThread method. To obtain an NSThread object that will create a new thread of execution, use detachNewThreadSelector:toTarget:withObject:. This method sends the specified Objective C message to the specified object in its own thread of execution. You use the NSThread object returned by these methods if you ever need to delay or terminate that thread of execution.

When you use detachNewThreadSelector:toTarget:withObject:, your application becomes multithreaded. At any time, you can send isMultiThreaded to find out if the application is multithreaded, that is, if a thread was ever detached from the current thread. isMultiThreaded returns YES even if the detached thread has completed execution.

Creating an NSThread

+ (NSThread *)currentThread	Returns an object representing the current thread of execution.

+ (void)detachNewThreadSelector:(SEL)aSelector	Creates and starts a new NSThread for the message 
toTarget:(id)aTarget		[aTarget aSelector:anArgument]. The method 
withObject:(id)anArgument		aSelector may take only one argument and may not have a return value. If this is the first thread detached from the current thread, this method posts the notification NSBecomingMultiThreaded will the nil object to the default notification center. 

Querying a Thread 

+ (BOOL)isMultiThreaded	Returns YES if a thread was ever detached (regardless of if the detached thread is still running).

- (NSMutableDictionary *)threadDictionary	Returns the NSThread's dictionary, allowing you to add data specific to the receiving NSThread. This essentially allows user-defined NSThread variables.

Delaying a Thread

+ (void)sleepUntilDate:(NSDate *)date	Has the receiving NSThread sleep until the time specified by date. No input or timers will be processed in this interval.

Terminating a Thread 

+ (void)exit	Terminates the thread represented by the calling object. Before exiting that thread, this method posts the NSThreadExiting notification with the thread being exited to the default notification center.