Re: code example on NSThread
Re: code example on NSThread
- Subject: Re: code example on NSThread
- From: Ondra Cada <email@hidden>
- Date: Mon, 29 Jul 2002 14:47:08 +0200
On Monday, July 29, 2002, at 11:53 , Chong Hiu Pun wrote:
May you some me some example on how to use NSThread?Thanks!
#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
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.