Re: NSThread
Re: NSThread
- Subject: Re: NSThread
- From: Ondra Cada <email@hidden>
- Date: Sun, 26 Aug 2001 15:34:25 +0200
Johan,
>
>>>>> Johan Lindberg (JL) wrote at Sun, 26 Aug 2001 15:21:50 +0200:
JL> I've been looking for some sample code, using NSThreads
Would this trivial sample suffice?
#import <Foundation/Foundation.h>
@interface Threader:NSObject
-(void)entryPoint:o;
@end
@implementation Threader
-(void)entryPoint:o {
id p=[NSAutoreleasePool new];
NSString *myname=[o objectAtIndex:0];
int delay=[[o objectAtIndex:1] intValue];
for (;;) {
NSLog(@"%@ again",myname);
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:delay]];
}
[p release]; // not that it would be ever called
}
@end
void main() {
id p=[NSAutoreleasePool new];
id oo=[Threader new];
[NSThread detachNewThreadSelector:@selector(entryPoint:) toTarget:oo
withObject:[NSArray arrayWithObjects:@"Second",@"1",nil]];
[NSThread detachNewThreadSelector:@selector(entryPoint:) toTarget:oo
withObject:[NSArray arrayWithObjects:@"Three",@"3",nil]];
for (;;) {
NSLog(@"Press ^C to kill them all!");
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:4]];
}
[p release]; // not that it would be ever called
}
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
References: | |
| >NSThread (From: Johan Lindberg <email@hidden>) |