[concurrency-interest] maximum number of shared lock
forReentrantReadWriteLock
Hu, Jinsong
jhu at glog.com
Thu Jul 7 13:11:23 EDT 2005
0x7FFF = 32767 in decimal.
-----Original Message-----
From: Bill Scherer [mailto:scherer at cs.rochester.edu]
Sent: Thursday, July 07, 2005 12:22 PM
To: Hu, Jinsong
Cc: Tim Peierls; concurrency-interest at altair.cs.oswego.edu
Subject: RE: [concurrency-interest] maximum number of shared lock
forReentrantReadWriteLock
If acquires is 0x7FFF, then that's the maximum of 65535 that Tim
mentioned
below, so throwing an exception is correct in this case.
-- Bill
On Thu, 7 Jul 2005, Hu, Jinsong wrote:
> Let's say that current state is 0x7FFF0000, hence the current total
> shared lock count is 0x7FFF. Now, let's acquire one more shared lock,
> hence following are values of current variables:
>
> int c = 0x7FFF0000
> int i = 1 << 16 = 0x00010000
> int nextc = c + i = 0x80000000 < 0
>
> hence nextc < c and according to the code, the lock overflow exception
> is still thrown out.
>
> Jinsong
>
>
>
> -----Original Message-----
> From: Tim Peierls [mailto:tim at peierls.net]
> Sent: Thursday, July 07, 2005 11:33 AM
> To: Hu, Jinsong
> Cc: concurrency-interest at altair.cs.oswego.edu
> Subject: Re: [concurrency-interest] maximum number of shared lock
> forReentrantReadWriteLock
>
> Your arithmetic is OK, but the acquires argument is always 1 for this
> RRWL
> method (though not in general with AQS), so nextc < c only on overflow
> of
> the shared count "field".
>
> The documentation *is* wrong about 65536; it should be 65535. I think
> this
> has been fixed for Mustang.
>
> --tim
>
>
> Hu, Jinsong wrote:
> > I found my self stuck on a basic bit number operation here, and I
hope
> I
> > am wrong here, following is the code I extracted from this class:
> >
> > /**
> > * Perform nonfair tryLock for read.
> > */
> > final int nonfairTryAcquireShared(int acquires) {
> > for (;;) {
> > int c = getState();
> > int nextc = c + (acquires << SHARED_SHIFT);
> > if (nextc < c)
> > throw new Error("Maximum lock count exceeded");
> > if (exclusiveCount(c) != 0 &&
> > owner != Thread.currentThread())
> > return -1;
> > if (compareAndSetState(c, nextc))
> > return 1;
> > // Recheck count if lost CAS
> > }
> > }
> >
> > Let's say, initially, c is 0, while I tried to acquire 0x80000
shared
>
> You meant 0x8000 here, right?
>
> > lock, then 0x8000 << 16 is a negative number, then c + 0x8000 << 16
is
>
> > definitely less than c, then the maximum lock count exceeded
exception
>
> > will be thrown out. If this is true, then the shared lock count can
> not
> > be beyond 0x8000 (32768), not 65536.
>
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>
More information about the Concurrency-interest
mailing list