Posted by trlists on 03/25/05 19:01
On 25 Mar 2005 Joshua Beall wrote:
> P1: "Does token.status = 'locked' WHERE key=$key ?"
> P2: "Does token.status = 'locked' WHERE key=$key ?"
> P1: {Receives negative response}
> P2: {Receives negative response}
> P1: Updates token.status. = 'locked' WHERE key=$key
> P2: Updates token.status. = 'locked' WHERE key=$key
The problem here is that the check / lock operation has to be "atomic",
that is you can't let a second process check or lock the resource while
the first is in the process of locking it. This is a basic issue for
any kind of semaphore, you have to be able to do an atomic "test and
set" or you get problems exactly as described above.
If it's a MySQL table then to me the simple solution is to use a LOCK
TABLES then test and set the token stored in the database, then UNLOCK
TABLES. But that might be a bit "expensive" in terms of overhead, and
you can probably find a way to do it with local files as well. Also
the shared memory functions look like they could be useful in this
regard, if supported on your platform.
--
Tom
[Back to original message]
|