Re: NSThread
Re: NSThread
- Subject: Re: NSThread
- From: Ondra Cada <email@hidden>
- Date: Thu, 9 May 2002 18:42:45 +0200
On Thursday, May 9, 2002, at 01:23 , Martin Weil wrote:
I need to have a simple thread, and i dont know how to put code into it,
perhaps anybody can hep me...
Would this simple example hep enough?
#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
2K Development: email@hidden
http://www.2kdevelopment.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.
References: | |
| >NSThread (From: Martin Weil <email@hidden>) |