3 ms·
Speaking of concurrent programming and parallelism. If you're not into functional programming, check out Apple's Grand Central Dispatch[1] and Objective-C Block
by SeoxyS 15y ago
Speaking of concurrent programming and parallelism. If you're not into functional programming, check out Apple's Grand Central Dispatch[1] and Objective-C Blocks[2].
Unless you write your own Objective-C http server and run it on Mac OS X Server (it's not that hard, I've done it), this isn't very useful for Web programming. However, if you're comparing the languages / frameworks themselves (you can use all three to code command line tools, for example), GCD becomes a very seductive option.
GCD works by throwing code blocks (obj-c closures) into queues, and letting the runtime do its magic. You can have it execute code synchronously, asynchronously, or in parallel.
GCD will optimize and distribute your blocks the the available CPU cores. You can even enumerate using blocks, and instead of doing loop iterations one by one, it'll distribute them to the cores in parallel.
[1]: http://en.wikipedia.org/wiki/Grand_Central_Dispatch http://en.wikipedia.org/wiki/Grand_Central_Dispatch
[2]: http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/Blocks/Articles/bxGettingStarted.html#//apple_ref/doc/uid/TP40007502-CH7-SW1 http://developer.apple.com/library/ios/#documentation/cocoa/...
- BasDirks 15y agoNode is very nice for command line tools!
- bittersweet 15y agoI've been hacking away on Obj-C and more specifically MacRuby and did some basic stuff with GCD already, using the async queueing system. The distributed enumeration sounds interesting, could you point me in the direction of where I can find some more info about that?
- SeoxyS 15y agoYou might wanna take a look at dispatch_apply with striding: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/dispatch_apply.3.html http://developer.apple.com/library/mac/#documentation/Darwin...