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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-novice by date

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