[Pyobjc-dev] Threading [Was: Re: Achieving 1.0....]
Brought to you by:
ronaldoussoren
|
From: Bill B. <bb...@co...> - 2002-10-30 01:10:08
|
On Tuesday, October 29, 2002, at 04:17 PM, Jack Jansen wrote:
> Something else you may want to try though, if this is needed for
> PyObjC, is to let the thread terminate. The comments in NSThread.h
> lead me to believe that once you've made the transition to a
> multithreaded program there's no going back. If that's indeed the case
> then letting the thread terminate isn't a problem.
I wrote a little hunk of code to verify the behavior and you are
correct-- a program can only become multithreaded, but will never
revert to single threaded. However, given that there is both a
NSWillBecomeMultiThreadedNotification and a
NSDidBecomeSingleThreadedNotification notification, it would seem that
Apple intends to someday support the transition from multi->single
threaded.
As such -- I would recommend leaving in the deadlocked thread.
NSDidBecomeSingleThreadedNotification is currently documented as "Not
Implemented.".
(To test this case, create a new "foundation tool" project and replace
the contents of main.m with the code shown below.
// --- start of code
#import <Foundation/Foundation.h>
@interface NSObject (TheVoid)
+ (void) intoTheVoid: aNothing;
@end
@implementation NSObject (TheVoid)
+ (void) intoTheVoid: aNothing;
{
/* NSLock *l = [[NSLock alloc] init];
[l lock];
[l lock];*/
}
- (void) receiveNotification: aNotification
{
NSLog(@"Recieved %@", aNotification);
}
- (void) timerFired: anObject
{
NSLog(@"Timer fired.");
}
@end
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
[[NSNotificationCenter defaultCenter]
addObserver: [NSObject class]
selector: @selector(receiveNotification:)
name: nil
object: nil];
[NSThread detachNewThreadSelector:@selector(intoTheVoid:)
toTarget:[NSObject class] withObject: nil];
[NSTimer scheduledTimerWithTimeInterval: 5.0
target: [NSObject class]
selector: @selector(timerFired:)
userInfo: nil
repeats: NO];
[[NSRunLoop currentRunLoop] runUntilDate: [NSDate distantFuture]];
[pool release];
return 0;
}
// ------- end of code
2002-10-29 18:19:29.512 threadtest[14834] Recieved
NSConcreteNotification 5a740 {name =
NSWillBecomeMultiThreadedNotification}
2002-10-29 18:19:29.558 threadtest[14834] Recieved
NSConcreteNotification 5a740 {name = _NSThreadDidStartNotification}
2002-10-29 18:19:29.629 threadtest[14834] Recieved
NSConcreteNotification 5cec0 {name = NSThreadWillExitNotification;
object = <NSThread: 0x5ce80>{num = 2, threadDictionary =
(null)
}}
2002-10-29 18:19:34.559 threadtest[14834] Timer fired.
threadtest has exited with status 0.
b.bum
We gladly feast on those who would subdue us.
|