[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Wed, 03 Nov 2004 14:07:18 +0200
After this change in -base
2004-09-27 Richard Frith-Macdonald <address@hidden>
* Source/NSThread.m: Refrain from creating thread dictionary in an
inactive thread ... we don't want to create new objects in a thread
which is in the process of exiting. Also, improve documentation.
that is, in GSDictionaryForThread() the line:
if (dict == nil)
if (dict == nil && ((NSThread_ivars *)t)->_active == YES)
I'm encountering problems with threads that doesn't exit anymore.
I'm using the following code in many places, where a long task, as a file
operation, is executed in an other thread. In all the places the code is
something like this:
In the main thread I detach a new thread:
ports = [NSArray arrayWithObjects: port, port, nil];
conn = [[NSConnection alloc] initWithReceivePort: port sendPort: port];
[conn setRootObject: self];
[conn setDelegate: self];
[nc addObserver: self
[NSThread detachNewThreadSelector: @selector(setPorts:)
toTarget: [Updater class]
- setPorts: creates a new instance of "Updater" and release it because it is
retained in the main thread:
conn = [NSConnection connectionWithReceivePort: (NSPort *)port
sendPort: (NSPort *)port];
updater = [[self alloc] init];
[updater setFileop: thePorts];
[(id)[conn rootProxy] registerUpdater: updater];
// "updater" is retained in "-registerUpdater:"
[[NSRunLoop currentRunLoop] run];
After doing its work "updater" notices the object in the main thread that has a
method like this:
[nc removeObserver: self
// we retained it in "-registerUpdater:"
In -exitThread method there is only a line:
but the thread doesn't exit and the cpu usage of the process grows to 99%.
Examples of this code are in Operation, Inspector, etc...
If you grep '[NSThread exit]' you will find all the places.
Enrico Sersale <=