tags:

views:

84

answers:

4

hi friends,

i want to execute two methods parallely. what should i have to do and how it is possible. is it possible using NSThread ? if yes then How ? waiting for your great responce.

Tanking you

A: 

check out NSOperation, and NSOperationQueue. http://www.cimgf.com/2008/02/16/cocoa-tutorial-nsoperation-and-nsoperationqueue/ That might do what you're looking for.

Kenny Winker
+2  A: 

While you can do it with NSOperation and NSThread, the easiest way to execute methods in the background is using performSelectorInBackground:withObject: or performSelector:onThread:withObject:waitUntilDone:modes::

// execute method1 and method2 in parallel
[self performSelectorInBackground:@selector(method1) withObject:nil];
[self performSelectorInBackground:@selector(method2) withObject:nil];

However, I think you need to create a new NSAutoReleasePool for those methods.

In general I would recommend reading Threading Programming Guide and Concurrency Programming Guide.

notnoop
A: 

see: @interface NSObject (NSThreadPerformAdditions)

Justin
A: 

It is possible using NSThread, but I believe Apple is trying to move people off of creating their own thread management, and towards the notion of submitting tasks that can run concurrently to each other. Previous posters already mentioned the NSOperation and NSOperationQueue, so I will not repeat their answers. If anyone is interest in learning more on this check the iPhone Concurrency Programming Guide at the iPhone Dev Center.

Brandon Bodnár