[eluser]d1a8lo24[/eluser]
I'm pretty sure you already thought of this but it doesn't hurt mentioning it.
Think of your application as a real store and lets say there are 10 ipods on the shelf and nothing in stock well if someone is shopping around with their cart they will grab 1 ipod and keep on shopping the shelf will now have 9 ipods for anyone else to view.
In your case what you want to do is update the quantity on the database when a person adds an item to their cart making the item quantities exact to whats available at that moment or at least that is the theory. And then if the person doesn't buy the item and this is where the coding will be a little complex add back the items not sold from either inactivity or any other none sale actions. This is the part to give it a little thought.
Most shopping carts out there don't have this real time item tracking feature but giving a little thought you can integrated.
You can also do a last check at checkout for quantities and then give the buyer more options to either go through with the transaction or to remove out of stock items.
I my self have sunshop shopping cart and I have run into this problems in the past all I was able to do was notify the customer about the availability and hope they will wait for their merchandise.
Sorry for no coding examples but i'm pretty sure you will get the idea if you're using CI cart class, which uses the sessions class to keep track of items and not on stock quantities.
As far as locking tables for what I know, I don't think it will be possible to implement to what you want since locking the table will prevent any updates to that table for any amount of time is being lock.