You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@bookkeeper.apache.org by Venkateswara Rao Jujjuri <ju...@gmail.com> on 2016/04/22 02:23:09 UTC

addEntry() is susceptible to spurious wakeups?

LedgerHandle sync interface heavily depends on SyncCounter to convert async
interfaces
into sync interfaces.

Usaylly

SyncCounter.inc()
asyncCall()
SyncCOunter.block(0)

The block code is.

   synchronized void block(int limit) throws InterruptedException {
        while (i > limit) {
            int prev = i;
            wait();
            if (i == prev) {
                break;
            }
        }
    }

Since 'i' is going to be same as 'prev' on spurious wakeup, and wait() can
return
on spurious wakeups, aren't we susceptible? or I am missing something here?

How about replacing SyncCounter with CountDownLatch.
If we agree, I can raise a ticket.

-- 
Jvrao
---
First they ignore you, then they laugh at you, then they fight you, then
you win. - Mahatma Gandhi

Re: addEntry() is susceptible to spurious wakeups?

Posted by Venkateswara Rao Jujjuri <ju...@gmail.com>.
Great; May be or may be not as CountDownLatch won't allow us to set the
value, you can set the value only at the object creation time. Will open a
Jira and may be take care of spurious wakeups first.

On Fri, Apr 22, 2016 at 9:30 AM, Matteo Merli <ma...@gmail.com>
wrote:

> Probably SyncCounter was introduced before CountdownLatch was available in
> jdk. I think it should be good to switch to countdown latch.
>
> On Fri, Apr 22, 2016 at 9:28 AM Venkateswara Rao Jujjuri <
> jujjuri@gmail.com>
> wrote:
>
> > I am mostly concerned about this logic in block() which makes us
> > susceptible to spurious wake-ups.
> >
> >             if (i == prev) {
> >                 break;
> >             }
> >
> > Anyone comments?
> >
> > On Thu, Apr 21, 2016 at 5:23 PM, Venkateswara Rao Jujjuri <
> > jujjuri@gmail.com
> > > wrote:
> >
> > > LedgerHandle sync interface heavily depends on SyncCounter to convert
> > > async interfaces
> > > into sync interfaces.
> > >
> > > Usaylly
> > >
> > > SyncCounter.inc()
> > > asyncCall()
> > > SyncCOunter.block(0)
> > >
> > > The block code is.
> > >
> > >    synchronized void block(int limit) throws InterruptedException {
> > >         while (i > limit) {
> > >             int prev = i;
> > >             wait();
> > >             if (i == prev) {
> > >                 break;
> > >             }
> > >         }
> > >     }
> > >
> > > Since 'i' is going to be same as 'prev' on spurious wakeup, and wait()
> > can
> > > return
> > > on spurious wakeups, aren't we susceptible? or I am missing something
> > here?
> > >
> > > How about replacing SyncCounter with CountDownLatch.
> > > If we agree, I can raise a ticket.
> > >
> > > --
> > > Jvrao
> > > ---
> > > First they ignore you, then they laugh at you, then they fight you,
> then
> > > you win. - Mahatma Gandhi
> > >
> > >
> > >
> >
> >
> > --
> > Jvrao
> > ---
> > First they ignore you, then they laugh at you, then they fight you, then
> > you win. - Mahatma Gandhi
> >
>



-- 
Jvrao
---
First they ignore you, then they laugh at you, then they fight you, then
you win. - Mahatma Gandhi

Re: addEntry() is susceptible to spurious wakeups?

Posted by Matteo Merli <ma...@gmail.com>.
Probably SyncCounter was introduced before CountdownLatch was available in
jdk. I think it should be good to switch to countdown latch.

On Fri, Apr 22, 2016 at 9:28 AM Venkateswara Rao Jujjuri <ju...@gmail.com>
wrote:

> I am mostly concerned about this logic in block() which makes us
> susceptible to spurious wake-ups.
>
>             if (i == prev) {
>                 break;
>             }
>
> Anyone comments?
>
> On Thu, Apr 21, 2016 at 5:23 PM, Venkateswara Rao Jujjuri <
> jujjuri@gmail.com
> > wrote:
>
> > LedgerHandle sync interface heavily depends on SyncCounter to convert
> > async interfaces
> > into sync interfaces.
> >
> > Usaylly
> >
> > SyncCounter.inc()
> > asyncCall()
> > SyncCOunter.block(0)
> >
> > The block code is.
> >
> >    synchronized void block(int limit) throws InterruptedException {
> >         while (i > limit) {
> >             int prev = i;
> >             wait();
> >             if (i == prev) {
> >                 break;
> >             }
> >         }
> >     }
> >
> > Since 'i' is going to be same as 'prev' on spurious wakeup, and wait()
> can
> > return
> > on spurious wakeups, aren't we susceptible? or I am missing something
> here?
> >
> > How about replacing SyncCounter with CountDownLatch.
> > If we agree, I can raise a ticket.
> >
> > --
> > Jvrao
> > ---
> > First they ignore you, then they laugh at you, then they fight you, then
> > you win. - Mahatma Gandhi
> >
> >
> >
>
>
> --
> Jvrao
> ---
> First they ignore you, then they laugh at you, then they fight you, then
> you win. - Mahatma Gandhi
>

Re: addEntry() is susceptible to spurious wakeups?

Posted by Venkateswara Rao Jujjuri <ju...@gmail.com>.
I am mostly concerned about this logic in block() which makes us
susceptible to spurious wake-ups.

            if (i == prev) {
                break;
            }

Anyone comments?

On Thu, Apr 21, 2016 at 5:23 PM, Venkateswara Rao Jujjuri <jujjuri@gmail.com
> wrote:

> LedgerHandle sync interface heavily depends on SyncCounter to convert
> async interfaces
> into sync interfaces.
>
> Usaylly
>
> SyncCounter.inc()
> asyncCall()
> SyncCOunter.block(0)
>
> The block code is.
>
>    synchronized void block(int limit) throws InterruptedException {
>         while (i > limit) {
>             int prev = i;
>             wait();
>             if (i == prev) {
>                 break;
>             }
>         }
>     }
>
> Since 'i' is going to be same as 'prev' on spurious wakeup, and wait() can
> return
> on spurious wakeups, aren't we susceptible? or I am missing something here?
>
> How about replacing SyncCounter with CountDownLatch.
> If we agree, I can raise a ticket.
>
> --
> Jvrao
> ---
> First they ignore you, then they laugh at you, then they fight you, then
> you win. - Mahatma Gandhi
>
>
>


-- 
Jvrao
---
First they ignore you, then they laugh at you, then they fight you, then
you win. - Mahatma Gandhi