|
+ ---- + ---------- + --------- +
| id | item | status |
+ ---- + ---------- + --------- +
| 1 | a | 1 |
+ ---- + ---------- + --------- +
| 2 | b | 0 |
+ ---- + ---------- + --------- +
| 3 | c | 0 |
+ ---- + ---------- + --------- +
| 4 | d | 0 |
+ ---- + ---------- + --------- +
| 5 | e | 0 |
+ ---- + ---------- + --------- +
| 6 | f | 0 |
+ ---- + ---------- + --------- +
| 7 | g | 0 |
+ ---- + ---------- + --------- +
There is a program that polls this table every time and selects the record with select top 1 * from tbl where status = 0, and then sets the status of this record to 1. The problem is that if it is multi-threaded, a thread may appear. This record has been fetched. Before it sets this record to 1, another thread fetches this record, and it appears that multiple identical data records have been fetched. How do you solve this problem? |
|