Jump to content
  • Advertisement
Sign in to follow this  
ms75214

threads on mac

This topic is 2754 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
this is good

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html#//apple_ref/doc/uid/10000057i-CH15-SW2

here's a synopsis


Using NSThread
There are two ways to create a thread using the NSThread class:

Share this post


Link to post
Share on other sites

this is good

https://developer.ap...00057i-CH15-SW2

here's a synopsis


Using NSThread
There are two ways to create a thread using the NSThread class:




i'm trying to do this

NSThread* myThread = [[NSThread alloc] initWithTarget:self selector:@selector(myThreadMainMethod:) object:nil];[myThread start]; // Actually create the thread


but, i need to figure out what
myThreadMainMethod looks like. any ideas how to declare it?


Share this post


Link to post
Share on other sites

[quote name='ms75214' timestamp='1299354975' post='4782180']
this is good

https://developer.ap...00057i-CH15-SW2

here's a synopsis


Using NSThread
There are two ways to create a thread using the NSThread class:




i'm trying to do this

NSThread* myThread = [[NSThread alloc] initWithTarget:self selector:@selector(myThreadMainMethod:) object:nil];[myThread start]; // Actually create the thread


but, i need to figure out what
myThreadMainMethod looks like. any ideas how to declare it?



[/quote]

ok, i think these are examples of threads

(void) _showMenuThread:(id)tag {
NSAutoreleasePool* p = [[NSAutoreleasePool alloc] init];
[self performSelectorOnMainThread:@selector(_showMenu:) withObject:tag waitUntilDone:YES];
[p release];
}

- (void) _playMacroThread:(id)tag {
NSAutoreleasePool* p = [[NSAutoreleasePool alloc] init];
[self _playMacro:tag];
[p release];
}
(void) _showMenuThread:(id)tag {
NSAutoreleasePool* p = [[NSAutoreleasePool alloc] init];
[self performSelectorOnMainThread:@selector(_showMenu:) withObject:tag waitUntilDone:YES];
[p release];
}

- (void) _playMacroThread:(id)tag {
NSAutoreleasePool* p = [[NSAutoreleasePool alloc] init];
[self _playMacro:tag];
[p release];
}

Share this post


Link to post
Share on other sites
actually, the docs mention this


- (void)myThreadMainRoutine
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Top-level pool

// Do thread work here.

[pool release]; // Release the objects in the pool.
}

Share this post


Link to post
Share on other sites
i tried pasting this in my .mm file

- (void)myThreadMainRoutine
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Top-level pool

// Do thread work here.

[pool release]; // Release the objects in the pool.
}


and, it says "missing context for method declaration


any ideas why?

Share this post


Link to post
Share on other sites

i tried pasting this in my .mm file

- (void)myThreadMainRoutine
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Top-level pool

// Do thread work here.

[pool release]; // Release the objects in the pool.
}


and, it says "missing context for method declaration


any ideas why?




i decided to just use posix threads

void* PosixThreadMainRoutine(void* data)
{
// Do some work here.

for (int ctr = 0; ctr < 100; ctr++)
{
printf("oook %d\n",ctr);
sleep(1);
}
return NULL;
}

void LaunchThread()
{
// Create the thread using POSIX routines.
pthread_attr_t attr;
pthread_t posixThreadID;
int returnVal;

returnVal = pthread_attr_init(&attr);
assert(!returnVal);
returnVal = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
assert(!returnVal);

int threadError = pthread_create(&posixThreadID, &attr, &PosixThreadMainRoutine, NULL);

returnVal = pthread_attr_destroy(&attr);
assert(!returnVal);
if (threadError != 0)
{
// Report an error.
}
}



- (IBAction) pushAction:(id)sender {

printf("button pushed\n");

LaunchThread();

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!