ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/Exchanger.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/Exchanger.java (file contents):
Revision 1.42 by dl, Mon Feb 13 13:27:53 2006 UTC vs.
Revision 1.43 by jsr166, Tue Feb 14 18:08:05 2006 UTC

# Line 351 | Line 351 | public class Exchanger<V> {
351       * based on the current thread's Thread.getId().  These hash codes
352       * have more uniform distribution properties with respect to small
353       * moduli (here 1-31) than do other simple hashing functions.
354 <     * To return an index between 0 and max, we use a cheap
354 >     *
355 >     * <p>To return an index between 0 and max, we use a cheap
356       * approximation to a mod operation, that also corrects for bias
357 <     * due to non-power-of-2 remaindering (see {@link Random#nextInt}).
358 <     * Bits of the hashcode are masked with "nbits", the ceiling power
359 <     * of two of table size (looked up in a table packed into three
360 <     * ints).  If too large, this is retried after rotating the hash by
361 <     * nbits bits, while forcing new top bit to 0, which guarantees
362 <     * eventual termination (although with a non-random-bias).  This
363 <     * requires an average of less than 2 tries for all table sizes,
364 <     * and has a maximum 2% difference from perfectly uniform slot
365 <     * probabilities when applied to all possible hash codes for sizes
366 <     * less than 32.
357 >     * due to non-power-of-2 remaindering (see {@link
358 >     * java.util.Random#nextInt}).  Bits of the hashcode are masked
359 >     * with "nbits", the ceiling power of two of table size (looked up
360 >     * in a table packed into three ints).  If too large, this is
361 >     * retried after rotating the hash by nbits bits, while forcing new
362 >     * top bit to 0, which guarantees eventual termination (although
363 >     * with a non-random-bias).  This requires an average of less than
364 >     * 2 tries for all table sizes, and has a maximum 2% difference
365 >     * from perfectly uniform slot probabilities when applied to all
366 >     * possible hash codes for sizes less than 32.
367       *
368       * @return a per-thread-random index, 0 <= index < max
369       */
# Line 383 | Line 384 | public class Exchanger<V> {
384      /**
385       * Creates a new slot at given index.  Called only when the slot
386       * appears to be null.  Relies on double-check using builtin
387 <     * locks, since they rarely contend. This in turn relies on the
387 >     * locks, since they rarely contend.  This in turn relies on the
388       * arena array being declared volatile.
389       *
390       * @param index the index to add slot at

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines