I have a MySQL database and an online website (with PHP running on the backend).
If user A sends money to B, but B sends money to A in the same time, there is a race condition.
There are several other more complicated race conditions than just sending money (e.g. trading several items simultaneously for several other items - each item corresponding to a row in a MySQL table).
In PHP, is there a global lock I can use which I can refer to by a user's ID?
Pseudo code of what I want:
lock_acquire($user_A->id);
lock_acquire($user_B->id);
//do some sensitive stuff between user A and user B
lock_release($user_A->id);
lock_release($user_B->id);
Is there such a function in PHP?
Thanks in advance!