Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make Dispatch::Queue#apply documentation less misleading

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...
commit afd97dd0e622d41a7fa86606dbed181a0db72403 1 parent 4c9e258
@ferrous26 ferrous26 authored
Showing with 4 additions and 3 deletions.
  1. +4 −3 gcd.c
View
7 gcd.c
@@ -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]
*

0 comments on commit afd97dd

Please sign in to comment.
Something went wrong with that request. Please try again.