Re: Getting the process ID

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux