The common bit of programming logic that I find in myself is often something like the following pseudocode:
Let X = some value
Let Database = some external Database handle
if !Database.contains(X):
SomeCalculation()
Database.insert(X)
However, in a multi-threaded program, we have a race condition. Thread A can check if it is Xin Database, find it, and then go to the call SomeCalculation(). Meanwhile, Thread B also checks if it is Xin Database, find it and do not insert a duplicate.
So, of course, this needs to be synchronized, for example:
Let X = some value
Let Database = some external Database handle
LockMutex()
if !Database.contains(X):
SomeCalculation()
Database.insert(X)
UnlockMutex()
, , , . Mutex , . , - "" . (, Database .)
, ?
, , , , .
, SQL, - NoSQL, - , . , -, Atomic Stored Procedures? ? -, - "Distributed Mutex"? , , , , ?
, , , , .