Skip to content

Commit

Permalink
Make Dispatch::Queue#apply documentation less misleading
Browse files Browse the repository at this point in the history
Claiming that the blocks are executed in parallel is not correct
since it depends on the type of queue being used, and even in that
case concurrency is not the same things as parallelism.

In the example, the array grows dynamically and the assignment
being performed in the block would not be thread-safe
(concurrency-safe?).
  • Loading branch information
ferrous26 committed Aug 25, 2012
1 parent 4c9e258 commit afd97dd
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions gcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,12 +612,13 @@ rb_block_applier(void *data, size_t ii)
* call-seq:
* gcdq.apply(count) { |index| block }
*
* Runs a block count number of times in parallel via
* Runs a block _count_ number of times asynchronously via
* dispatch_apply(3)[http://developer.apple.com/mac/library/DOCUMENTATION/Darwin/Reference/ManPages/man3/dispatch_apply.3.html],
* passing in an index and waiting until all of them are done
* passing in an index and waiting until all of them are done.
* You must use a concurrent queue to run the blocks concurrently.
*
* gcdq = Dispatch::Queue.new('doc')
* @result = []
* @result = Array.new(5)
* gcdq.apply(5) {|i| @result[i] = i*i }
* p @result #=> [0, 1, 4, 9, 16]
*
Expand Down

0 comments on commit afd97dd

Please sign in to comment.