• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSThread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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>)

  • Prev by Date: Re: Docs
  • Next by Date: Re: Another way to set the system time zone???
  • Previous by thread: NSThread
  • Next by thread: Re: NSThread
  • Index(es):
    • Date
    • Thread