|
Posted by Gordon Burditt on 10/08/45 11:26
>Hello. I have a database which I have abstracted off with a set of
>functions I have written. (So all the correct quoting and unquoting are all
>in one place.)
>
>/* Simplified code. */
>
>$tokenCount = getTokenCount($userIdx);
>/* Context switch! */
>setTokenCount($userIdx, $tokenCount + 1);
>
>But what if another process perfoms a get on the same record between the
>get and the set of the first process? What I could do with is a mutex.
>
>Do they please exist for PHP running under Apache?
If you perform a query like:
update foo set bar=bar+1 where id = '$userIdx';
it should be atomic in the database without the need for explicit
locks, as it's all done in one SQL statement.
If your abstractions provide only the ability to read and write
things, not atomic increments and decrements, perhaps your design
needs changing.
Gordon L. Burditt
Navigation:
[Reply to this message]
|