ObjFW
|
A class which provides portable threads. More...
#import <OFThread.h>
Public Member Functions | |
(id) | - initWithObject: |
Initializes an already allocated thread with the specified object. | |
(id) | - initWithBlock: |
Initializes an already allocated thread with the specified block. | |
(id) | - initWithBlock:object: |
Initializes an already allocated thread with the specified block and object. | |
(id) | - main |
The main routine of the thread. You need to reimplement this! | |
(void) | - handleTermination |
This routine is exectued when the thread's main method has finished executing or terminate has been called. | |
(void) | - start |
Starts the thread. | |
(id) | - join |
Joins a thread. | |
Static Public Member Functions | |
(id) | + thread |
Creates a new thread. | |
(id) | + threadWithObject: |
Creates a new thread with the specified object. | |
(id) | + threadWithBlock: |
Creates a new thread with the specified block. | |
(id) | + threadWithBlock:object: |
Creates a new thread with the specified block and object. | |
(void) | + setObject:forTLSKey: |
Sets the Thread Local Storage for the specified key. | |
(id) | + objectForTLSKey: |
Returns the object for the specified Thread Local Storage key. | |
(OFThread *) | + currentThread |
Returns the current thread. | |
(void) | + sleepForTimeInterval: |
Suspends execution of the current thread for the specified time interval. | |
(void) | + sleepUntilDate: |
Suspends execution of the current thread until the specified date. | |
(void) | + yield |
Yields a processor voluntarily and moves the thread at the end of the queue for its priority. | |
(void) | + terminate |
Terminates the current thread, letting it return nil. | |
(void) | + terminateWithObject: |
Terminates the current thread, letting it return the specified object. |
A class which provides portable threads.
To use it, you should create a new class derived from it and reimplement main.
+ (OFThread *) currentThread |
Returns the current thread.
- (id) initWithBlock: | (of_thread_block_t) | block |
Initializes an already allocated thread with the specified block.
block | A block which is executed by the thread |
- (id) initWithBlock: | (of_thread_block_t) | block | |
object: | (id) | object | |
Initializes an already allocated thread with the specified block and object.
block | A block which is executed by the thread |
object | An object which is passed for use in the main method or nil |
- (id) initWithObject: | (id) | object |
Initializes an already allocated thread with the specified object.
object | An object which is passed for use in the main method or nil |
- (id) join |
Joins a thread.
- (id) main |
The main routine of the thread. You need to reimplement this!
It can access the object passed to the threadWithObject or initWithObject method using the instance variable named object.
+ (id) objectForTLSKey: | (OFTLSKey*) | key |
Returns the object for the specified Thread Local Storage key.
The returned object is not retained and autoreleased for performance reasons!
key | The Thread Local Storage key |
+ (void) setObject: | (id) | object | |
forTLSKey: | (OFTLSKey*) | key | |
Sets the Thread Local Storage for the specified key.
The specified object is first retained and then the object stored before is released. You can specify nil as object if you want the old object to be released and don't want any new object for the TLS key.
key | The Thread Local Storage key |
object | The object the Thread Local Storage key will be set to |
+ (void) sleepForTimeInterval: | (double) | seconds |
Suspends execution of the current thread for the specified time interval.
seconds | The number of seconds to sleep |
+ (void) sleepUntilDate: | (OFDate*) | date |
Suspends execution of the current thread until the specified date.
date | The date to wait for |
+ (void) terminateWithObject: | (id) | object |
Terminates the current thread, letting it return the specified object.
object | The object which the terminated thread will return |
+ (id) thread |
Creates a new thread.
+ (id) threadWithBlock: | (of_thread_block_t) | block |
Creates a new thread with the specified block.
block | A block which is executed by the thread |
+ (id) threadWithBlock: | (of_thread_block_t) | block | |
object: | (id) | object | |
Creates a new thread with the specified block and object.
block | A block which is executed by the thread |
object | An object which is passed for use in the main method or nil |
+ (id) threadWithObject: | (id) | object |
Creates a new thread with the specified object.
object | An object which is passed for use in the main method or nil |