473,383 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Mutex access on a database?

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?

Bill, lost update.

--
http://billpg.me.uk/ usenet(at)billpg(dot)me(dot)uk
Sep 12 '05 #1
3 4299
>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
Sep 12 '05 #2
go****@hammy.burditt.org (Gordon Burditt) wrote:
If you perform a query like:
update foo set bar=bar+1 where id = '$userIdx';
Ah ha. I must confess, I only know SQL from cribbing the commands
phpMyAdmin creates. I didn't realise you could do that.
it should be atomic in the database without the need for explicit
locks, as it's all done in one SQL statement.
If the database server (MySQL) will enforce atomic access, thats perfect.
If your abstractions provide only the ability to read and write
things, not atomic increments and decrements, perhaps your design
needs changing.


I'm still in the poke-about-with-prototype-code phase, so no worries.
Thanks.

Bill, incremental.

--
http://billpg.me.uk/ usenet(at)billpg(dot)me(dot)uk
Sep 12 '05 #3
Bill Godfrey wrote:
go****@hammy.burditt.org (Gordon Burditt) wrote:
If you perform a query like:
update foo set bar=bar+1 where id = '$userIdx';


Ah ha. I must confess, I only know SQL from cribbing the commands
phpMyAdmin creates. I didn't realise you could do that.
it should be atomic in the database without the need for explicit
locks, as it's all done in one SQL statement.


If the database server (MySQL) will enforce atomic access, thats perfect.


Presumably because you want to read either the prev or new value? In that
case you'll need to lock the tables first:

LOCK TABLES foo READ;
SELECT bar FROM foo WHERE id = '$userIdx';
UPDATE foo SET bar=bar+1 WHERE id = '$userIdx';
SELECT bar FROM foo WHERE id = '$userIdx';
UNLOCK TABLES;

(quick hack, not tested YMMV)

C.
Sep 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ken Varn | last post by:
I have a named mutex object that is accessed by both an asp.net application and a Windows executable .net application. The Windows executable runs under the administrator logon, while the asp.net...
4
by: Vinay C | last post by:
Hi, Can anyone clear me that, when should we use go for mutex, and in which situation should we opt for monitor, lock, semaphone and other objects, in a multithreaded application for synchronization...
193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
2
by: Martin Maat | last post by:
Hi. I want to use the same mutex in different classes (web pages in an ASP.NET application). In global.asax.cs, the class that starts up first, I create a Mutex like this: static private...
1
by: Kris | last post by:
I want to set a mutex in one windows account and allow another windows account to access this mutex. For testing I have two forms that create a mutex using the C# mutex class. I am logging into...
1
by: Lloyd Dupont | last post by:
I have some code where I updatde a file (that might not exist yet). In fact this file contains 2 integers and is used in only one function. I thought overkill to configure, deploy and maintain a...
2
by: tony.newsgrps | last post by:
Hi there, I'm trying to understand the impact of killing a process that owns a system mutex (used to ensure there is only 1 instance of my program running) Here is my code pretty much: try...
2
by: tshad | last post by:
I am running a program as a Windows service which works fine. I am using a Mutex to prevent multiple threads from from accessing my log text file at the same time. It works fine in the Service:...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.