i'm creating a browser rpg game where the player has an inventory and a warehouse. Imagine that at some point, a user wants to move an item from the inventory to the warehouse. And now the security has to be tight.
I suppose that this has to be a transaction. Now, you see the possibilities for a race condition here. Move from inv->warehouse at the same time as move from warehouse->inv could mean that an item is duplicated.
So, how can i handle that to make sure nothing like that happens ?
EDIT -- RACE CONDITION FOR THAT EXAMPLE
Moving from inv to warehouse is a function where the item from inv is first added to warehouse and then deleted from the inventory. Moving from warehouse to inv is the same idea.
Now, think of 2 simultaneous moves. An inv moving function adds item to warehouse. At the very same time, the opposite begins. A warehouse moves the exact item to inventory. It will find the item to move, since it was just moved. The inventory now deletes item from inventory. The warehouse deletes item from warehouse.
Result : Item is lost