Skip site navigation (1) Skip section navigation (2)

Buggy SELEC ... FROM UPDATE ?

From: Patrice Espié <patrice(dot)espie(at)univ-lyon2(dot)fr>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Buggy SELEC ... FROM UPDATE ?
Date: 2001-04-10 14:30:18
Message-ID: 008101c0c1ca$c47d8990$0400a8c0@univlyon2.fr (view raw or flat)
Thread:
Lists: pgsql-novice
Hello, (bis)

I try to use SELECT FOR UPDATE, but it seems to be buggy, hum ? Perhaps it's
my algorythm...

My syslock table:
---------------
id   integer
used boolean
---------------

Here is the algo:
---------------
boolean Got = false
while Got == false
    Start transaction
    SELECT * FROM syslock WHERE id=%d AND used='f' FOR UPDATE
    if SELECT returns a row
    then
        UPDATE syslock SET used='t' WHERE id=%d
        Commit transaction
        Got = true
    else
        Rollback transaction
        continue // yes, active wait ... I'm testing !
    end if
end while
Trace "I get the syslock number %d !!"
Do something with the syslock %d which is now reserved
UPDATE syslock SET used='f' WHERE id=%d
---------------

When a lot of threads (well, I tried 20, 5 and 2) used this algo, more than
one thread get the syslock %d at the same time.

What is the problem ?

Thanks
Patrice Espié
--
Le Monde, c'est comme un éléphant
qui va à la pêche



Responses

pgsql-novice by date

Next:From: Helge BahmannDate: 2001-04-10 14:39:01
Subject: Re: Buggy SELEC ... FROM UPDATE ?
Previous:From: Patrice EspiéDate: 2001-04-10 12:34:34
Subject: Lock : How to know if a row is locked ?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group