macOS
last updated 2012-12
asynchronous execution
here are 3 methods of executing code asynchronously
using NSThread (and threading in general) is the usual way, recommended for longer-running threads
the other 2 methods are typically recommended for use "locally", that is limited to the lifetime of the object that spawns the async code
NSThread
TODO
performSelectorInBackground:withObject:
the performSelectorInBackground method of NSObject spawns a new thread to execute your provided method (via selector)
this also means that you have to take care of your releases or create a release pool, just as with NSThread
typical usage:
- (void)mainMethod
{
// ...
[self performSelectorInBackground:@selector(asyncMethod:) withObject:someParam];
// code here is executed (almost) immediately after the above call,
// as the asyncMethod's code is now being executed in separate thread
// ...
}
NSArray* foo = [[[NSArray alloc] initWithObjects:@"a", @"b", nil] autorelease];
[bar performSelectorInBackground:@selector(baz:) withObject:foo];
- (void)asyncMethod:(id)param
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
// your code that will be executed asynchronously
[pool release];
}
dispatch_async()
TODO
updating and cleaning up MacPorts
$ sudo port selfupdate
$ sudo port upgrade outdated
$ sudo port uninstall inactive
$ (just once) sudo port install port_cutleaves
$ sudo port_cutleaves