OFThread Class Reference

A class which provides portable threads. More...

#import <OFThread.h>

Inheritance diagram for OFThread:
OFObject

List of all members.

Public Types

enum  { OF_THREAD_NOT_RUNNING, OF_THREAD_RUNNING, OF_THREAD_WAITING_FOR_JOIN }

Public Member Functions

(id) - initWithObject:
(id) - main
(void) - handleTermination
(void) - start
(id) - join

Static Public Member Functions

(id) + threadWithObject:
(id) + setObject:forTLSKey:
(id) + objectForTLSKey:
(OFThread *) + currentThread
(void) + sleepForNMilliseconds:
(void) + yield
(void) + terminate
(void) + terminateWithObject:

Public Attributes

enum OFThread:: { ... }  running
id retval

Protected Attributes

id object
of_thread_t thread

Detailed Description

A class which provides portable threads.

To use it, you should create a new class derived from it and reimplement main.


Member Function Documentation

+ (OFThread *) currentThread  
Returns:
The current thread or nil if we are in the main thread
- (void) handleTermination  

This routine is exectued when the thread's main method has finished executing or terminate has been called.

- (id) initWithObject: (id)  obj  
Parameters:
obj An object that is passed to the main method as a copy or nil
Returns:
An initialized OFThread.
- (id) join  

Joins a thread.

Returns:
The object returned by the main method of the 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.

Returns:
The object the join method should return when called for this thread
+ (id) objectForTLSKey: (OFTLSKey*)  key  

Returns the object for the specified Thread Local Storage key.

Parameters:
key The Thread Local Storage key
+ (id) setObject: (OFObject*)  obj
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.

Parameters:
key The Thread Local Storage key
obj The object the Thread Local Storage key will be set to
Returns:
The old object, autoreleased
+ (void) sleepForNMilliseconds: (unsigned int)  msecs  

Suspends execution of the current thread for N milliseconds.

- (void) start  

Starts the thread.

+ (void) terminate  

Terminates the current thread, letting it return nil.

+ (void) terminateWithObject: (id)  obj  

Terminates the current thread, letting it return the specified object.

Parameters:
The object which the terminated thread will return
+ (id) threadWithObject: (id)  obj  
Parameters:
obj An object that is passed to the main method as a copy or nil
Returns:
A new autoreleased thread
+ (void) yield  

Yields a processor voluntarily and moves the thread at the end of the queue for its priority.


The documentation for this class was generated from the following files:
 All Classes Functions Variables
Generated on Sun May 9 16:52:22 2010 for ObjFW by  doxygen 1.6.3