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

Comparing jsr166/src/main/java/util/concurrent/Semaphore.java (file contents):
Revision 1.35 by dl, Thu Jan 8 01:28:48 2004 UTC vs.
Revision 1.36 by dl, Fri Jan 9 14:45:17 2004 UTC

# Line 88 | Line 88 | import java.util.concurrent.atomic.*;
88   * ownership).  This can be useful in some specialized contexts, such
89   * as deadlock recovery.
90   *
91 < * <p> The constructor for this class accepts a <em>fairness</em>
92 < * parameter. When set false, this class makes no guarantees about the
93 < * order in which threads acquire permits. In particular, <em>barging</em> is
94 < * permitted, that is, a thread invoking {@link #acquire} can be
95 < * allocated a permit ahead of a thread that has been waiting.  When
96 < * fairness is set true, the semaphore guarantees that threads
97 < * invoking any of the {@link #acquire() acquire} methods are
98 < * allocated permits in the order in which their invocation of those
99 < * methods was processed (first-in-first-out; FIFO). Note that FIFO
100 < * ordering necessarily applies to specific internal points of
101 < * execution within these methods.  So, it is possible for one thread
102 < * to invoke <tt>acquire</tt> before another, but reach the ordering
103 < * point after the other, and similarly upon return from the method.
91 > * <p> The constructor for this class optionally accepts a
92 > * <em>fairness</em> parameter. When set false, this class makes no
93 > * guarantees about the order in which threads acquire permits. In
94 > * particular, <em>barging</em> is permitted, that is, a thread
95 > * invoking {@link #acquire} can be allocated a permit ahead of a
96 > * thread that has been waiting.  When fairness is set true, the
97 > * semaphore guarantees that threads invoking any of the {@link
98 > * #acquire() acquire} methods are allocated permits in the order in
99 > * which their invocation of those methods was processed
100 > * (first-in-first-out; FIFO). Note that FIFO ordering necessarily
101 > * applies to specific internal points of execution within these
102 > * methods.  So, it is possible for one thread to invoke
103 > * <tt>acquire</tt> before another, but reach the ordering point after
104 > * the other, and similarly upon return from the method.
105   *
106   * <p>Generally, semaphores used to control resource access should be
107   * initialized as fair, to ensure that no thread is starved out from
# Line 211 | Line 212 | public class Semaphore implements java.i
212  
213      /**
214       * Construct a <tt>Semaphore</tt> with the given number of
215 +     * permits and nonfair fairness setting.
216 +     * @param permits the initial number of permits available. This
217 +     * value may be negative, in which case releases must
218 +     * occur before any acquires will be granted.
219 +     */
220 +    public Semaphore(int permits) {
221 +        sync = new NonfairSync(permits);
222 +    }
223 +
224 +    /**
225 +     * Construct a <tt>Semaphore</tt> with the given number of
226       * permits and the given fairness setting.
227       * @param permits the initial number of permits available. This
228       * value may be negative, in which case releases must
# Line 348 | Line 360 | public class Semaphore implements java.i
360       */
361      public boolean tryAcquire(long timeout, TimeUnit unit)
362          throws InterruptedException {
363 <        return sync.acquireSharedTimed(1, unit.toNanos(timeout));
363 >        return sync.acquireSharedNanos(1, unit.toNanos(timeout));
364      }
365  
366      /**
# Line 526 | Line 538 | public class Semaphore implements java.i
538      public boolean tryAcquire(int permits, long timeout, TimeUnit unit)
539          throws InterruptedException {
540          if (permits < 0) throw new IllegalArgumentException();
541 <        return sync.acquireSharedTimed(permits, unit.toNanos(timeout));
541 >        return sync.acquireSharedNanos(permits, unit.toNanos(timeout));
542      }
543  
544      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines