I am working on an NFT collection of 10,000 images (1000 images per character). I want to allow users to pay a premium to mint a chosen character, and was thinking of storing a mapping of tokenIds to wallet addresses where IDs 0-1000 represent character 1, 1001-2000 represent character 2, etc. I was wondering how this/whether this works with concurrent transactions? Let's say two buyers want to buy character 2, so we start at key 1001 and look until we have an empty owner. Would it be possible for both buyers to end up with the same token ID?
I haven't notice any concurrency synchronization mechanism in solidity which should open the possibility for dirty data (e.g. variable is overriden by another thread) and ambiguity of the ownership (e.g. two users 'owns' the same id).
However there is such thing like consensus which would confirm a whole chain as common truth including a new block with your transaction.
Let's consider your case in theory. As there is two users where each of them performs the action on the chain, there would be two transactions and in case of ambiguity in data there would be two chains - a fork in the one origin chain. Nodes consensus would decide which branch to keep and which one discard. It should resolve ambiguity, but it leaves open issue with dirty data. Ethereum should resolves it too.
This is my current understanding. Let's see what others community members will share.