Authors
- Richard Frith-Macdonald (
rfm@gnu.org
)
-
Copyright: (C) 2010 Free Software Foundation, Inc.
- Declared in:
- GSIOThreadPool.h
This class provides a thread pool for performing methods
which need to make use of a runloop for I/O and/or
timers.
Operations are performed on these
threads using the standard
-performSelector:onThread:withObject:waitUntilDone:
method... the pool is simply used to keep track of allocation of threads so that you can share jobs between them.
NB. The threading API in OSX 10.4 and earlier is incapable of supporting this functionality... in that case this class cannot be instantiated and initialised.
Instance Variables
Method summary
+ (
GSIOThreadPool*)
sharedPool;
Returns an instance intended for sharing between
sections of code which wish to make use of
threading by performing operations in other
threads, but which don't mind operations being
interleaved with those belonging to oither
sections of code.
Always returns the same
instance whenever the method is called.
- (NSThread*)
acquireThread;
Selects a thread from the pool to be used for some
job.
- (
NSUInteger)
countForThread: (NSThread*)aThread;
Returns the acquire count for the specified thread.
- (
NSUInteger)
maxThreads;
Returns the currently configured maximum number of
threads in the pool.
- (void)
setThreads: (
NSUInteger)max;
Specify the maximum number of threads in the pool
(the actual number used may be lower than this value).
Default is 0 (no thread pooling in use).
The pool creates threads on demand up to the
specified limit (or a lower limit if dictated by
system resources) but will not destroy idle threads
unless the limit is subsequently lowered.
Setting a value of zero means that operations are
performed in the main thread.
- (void)
setTimeout: (NSTimeInterval)t;
Specifies the timeout allowed for a thread to
close down when the pool is deallocated or has its
size decreased. Any operations in progress in the
thread need to close down within this period.
- (NSTimeInterval)
timeout;
Returns the current timeout set for the pool.
- (void)
unacquireThread: (NSThread*)aThread;
Releases a thread previously selected from the
pool.
Instance Variables for GSIOThreadPool Class
@protected NSUInteger maxThreads;
Description forthcoming.
@protected NSLock* poolLock;
Description forthcoming.
@protected NSMutableArray* threads;
Description forthcoming.
@protected NSTimeInterval timeout;
Description forthcoming.
typedef unsigned int NSUInteger;
Description forthcoming.