Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Threading in Objective-C

Are there threads in Objective C? If so, how are they declared and used?

If anybody knows about multithreading in Objective C, please share with me.

Thanks and regards.

like image 348
Raju Avatar asked May 29 '09 11:05

Raju


1 Answers

An easy way to just spin off a method in a new thread is to use.

+ (void)detachNewThreadSelector:(SEL)aSelector toTarget:(id)aTarget withObject:(id)anArgument on NSThread. If you aren't running garbage collected you need to set up your own autorelease pool.

Another easy way if you just don't want to block the main thread is to use.

- (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg on NSObject

Depending on what type of concurrency you are after you should also take a look at NSOperation that can give you free locking so you can share it between several threads among other things.

like image 65
monowerker Avatar answered Sep 22 '22 01:09

monowerker