Race conditions

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ZxSpectrum
Forum Newbie
Posts: 11
Joined: Wed Feb 20, 2008 4:09 am

Race conditions

Post by ZxSpectrum »

Hello, i have the following problem:

In a web-game there is a sort of arena in which the players can kill themselves, but everything happens in real time.

Now, I have a problem when two people click the Attack link at the same time.

Before trying to kill the other char, the software checks if the other one is alive, but if the players click the links at the same time (they attack each other simultaneously), the two selects on the db see they are both alive, and this results in a double kill.

I think i have to set up a kind of lock mechanism, anyone of you has implemented something like this or can point me to some documentation?

Thanks
Post Reply