Re: Getting the process ID

From: Date: Fri, 25 Mar 2005 17:01:50 +0000
Subject: Re: Getting the process ID
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-211583@lists.php.net to get a copy of this message
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

« previous php.general (#211583) next »