On Mar 14, 2012, at 2:09 PM, Wade Tregaskis <wadesli...@mac.com> wrote:

>> I don't like the idea of a multithreaded aproach by default, because as a 
>> general rule, you
>> should not make your application multithreaded unless you have a good
>> reason.
> 
> b) This convenientional wisdom is, in my humble opinion, antiquated.

Indeed; I think a better approach is to express conceptual concurrency as 
naturally as possible, and let the underlying system manage any actual 
concurrency.

For example, if you're working on something that's essentially a 
producer-consumer problem, write it as such ― including appropriate control of 
access to shared resources ― and use a higher level abstraction like GCD or 
NSOperation in your implementation.

It'll be more work than two for loops in sequence, but at the low end it 
shouldn't be noticeably slower and at the high end it can be much faster. And 
it can have other benefits like lowering your memory footprint or high-water 
mark as a result (since you can avoid computing a complete set of intermediate 
results even on a single-core system).

Of course you need to consider the flip side too: Some resources are naturally 
constrained, such as access to a server via a single connection, or access to a 
single physical disk. But expressing the natural concurrency of a problem well 
can also help here, by giving you plenty of "knobs" with which to tweak your 
various forms of concurrency.

For example, you may use a queue with width 1 to fetch data from a server, a 
separate queue with system-managed concurrency to process that data (in one or 
several stages), a third queue with a width of 1 to save the processed data to 
disk, and the main queue to update your UI with the results of that processing. 
Everything will wind up appropriately pipelined for whatever system you use it 
on to make the best use of its available resources.

  -- Chris


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to