RE: Assuming that TAS() will succeed the first time is verboten

From: "Mikheev, Vadim" <vmikheev(at)SECTORBASE(dot)COM>
To: "'Tom Lane'" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: RE: Assuming that TAS() will succeed the first time is verboten
Date: 2000-12-28 22:11:46
Message-ID: 8F4C99C66D04D4118F580090272A7A234D321E@sectorbase1.sectorbase.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Ok.

> -----Original Message-----
> From: Tom Lane [mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us]
> Sent: Thursday, December 28, 2000 2:07 PM
> To: Mikheev, Vadim
> Cc: pgsql-hackers(at)postgreSQL(dot)org
> Subject: Re: Assuming that TAS() will succeed the first time
> is verboten
>
>
>
> "Mikheev, Vadim" <vmikheev(at)SECTORBASE(dot)COM> writes:
> > Anyway I don't object if it bothers you -:)
> > But please do not use S_LOCK - as you see WAL code try to do other
> > things if slock of "primary interest" is busy.
>
> In some places, yes. But I also saw a number of places where
> S_LOCK is
> sufficient, and I think it's clearer to code that way whenever there's
> not useful work to do before acquiring the lock. For example, is
>
> if (updrqst)
> {
> unsigned i = 0;
>
> for (;;)
> {
> if (!TAS(&(XLogCtl->info_lck)))
> {
> if (XLByteLT(XLogCtl->LgwrRqst.Write, LgwrRqst.Write))
> XLogCtl->LgwrRqst.Write = LgwrRqst.Write;
> S_UNLOCK(&(XLogCtl->info_lck));
> break;
> }
> s_lock_sleep(i++);
> }
> }
>
> really better than
>
> if (updrqst)
> {
> S_LOCK(&(XLogCtl->info_lck));
> if (XLByteLT(XLogCtl->LgwrRqst.Write, LgwrRqst.Write))
> XLogCtl->LgwrRqst.Write = LgwrRqst.Write;
> S_UNLOCK(&(XLogCtl->info_lck));
> }
>
> ? I don't think so...
>
> What I'm thinking of doing for the places where there is useful work
> to do while waiting is
>
> spins = 0;
> while (TAS(lock))
> {
> /* do useful work here */
> S_LOCK_SLEEP(spins++);
> }
>
> where S_LOCK_SLEEP() expands to do the same things as the body of the
> existing loop in s_lock().
>
> regards, tom lane
>

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2000-12-28 22:12:22 Re: Assuming that TAS() will succeed the first time is verboten
Previous Message Tom Lane 2000-12-28 22:06:55 Re: Assuming that TAS() will succeed the first time is verboten