• 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
NSTimer in a secondary thread?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTimer in a secondary thread?


  • Subject: NSTimer in a secondary thread?
  • From: Pierre-Olivier Latour <email@hidden>
  • Date: Wed, 21 Aug 2002 22:33:42 +0200

Hi,

I'm encapsulating my 3D engine inside a Cocoa interface. I'd like to do
rendering in a separate thread. However, I don't find the documentation very
clear on how to run an NSTimer inside another thread.

I'm trying the following code, but it does not work (the app crash about one
second after startup):

*****

- (void) catch:(NSTimer*)timer
{
NSLog(@"CATCH!");
}

- (void) test:(id)sender
{
NSAutoreleasePool* pool;
NSRunLoop* runLoop;
NSTimer* timer;

//Create an autorelease pool
pool = [[NSAutoreleasePool alloc] init];

//Add timer
runLoop = [NSRunLoop currentRunLoop];
timer = [NSTimer timerWithTimeInterval:1.0 target:self
selector:@selector(catch:) userInfo:NULL repeats:YES];
[runLoop addTimer:[timer retain] forMode:[runLoop currentMode]];

//Clear autorelease pool
[pool release];

NSLog(@"Exit!");
}

[NSThread detachNewThreadSelector:@selector(test:) toTarget:self
withObject:nil];

*****

Neither NSLog are called apparently.

What's the best method for my objective by the way? Should I use a NSTimer
or use low-level functions like "runMode:beforeDate:"? Or even do this:

while(1) {
[openGLView lockFocus];
render_frame();
[openGLView unlockFocus];
}

This solution seems to works fine, but I can't limit the framerate...

_____________________________________________________________

Pierre-Olivier Latour email@hidden
Lausanne, Switzerland http://www.pol-online.net
_______________________________________________
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.

  • Follow-Ups:
    • Re: NSTimer in a secondary thread?
      • From: Aram Greenman <email@hidden>
    • Re: NSTimer in a secondary thread?
      • From: Finlay Dobbie <email@hidden>
  • Prev by Date: Re: application connection surveillance
  • Next by Date: Re: transparent NSTextView
  • Previous by thread: Re: application connection surveillance
  • Next by thread: Re: NSTimer in a secondary thread?
  • Index(es):
    • Date
    • Thread