Leopard: NSOperation and NSOperationQueue Example
2007-11-17
Drew McCormack at MacResearch has a nice example of the power of NSOperation and NSOperationQueue. His example carries out matrix calculations using multiple threads by setting up an NSOperation to evaluate each part of an expression tree.
Usually it is hard to use CPU resources efficiently and reliably, but these new features of Leopard make it simple. By packaging compute-intensive operations into NSOperation objects all the complexity is handed off to the operating system.
Notable in this example is that there is no code for locking. That's all handled automatically. There is also no code to manage dependencies between parts of the expression that are being evaluated on multiple threads and potentially multiple CPUs. Dependencies are expressed in the code, but not explicitly managed.
Since this is Objective-C 2.0 you can also see @properties and @synthesize at work. And marvel at the lack of memory management.
The site also has many other goodies for people using Macs for scientific environments including a script repository, and a Core Animation tutorial.
Usually it is hard to use CPU resources efficiently and reliably, but these new features of Leopard make it simple. By packaging compute-intensive operations into NSOperation objects all the complexity is handed off to the operating system.
Notable in this example is that there is no code for locking. That's all handled automatically. There is also no code to manage dependencies between parts of the expression that are being evaluated on multiple threads and potentially multiple CPUs. Dependencies are expressed in the code, but not explicitly managed.
Since this is Objective-C 2.0 you can also see @properties and @synthesize at work. And marvel at the lack of memory management.
The site also has many other goodies for people using Macs for scientific environments including a script repository, and a Core Animation tutorial.
The Bagelturf site welcomes Donations of any size