Provided that only conditions and increment / decrement are used. I want to speed up the work of a multithreaded application. Interested in how unsafe it is in terms of an error.
If the treatment is read-only or access to the data is atomic, then it is safe. Otherwise, there is the possibility of poorly predictable racing.
In the case of increment and decrement, it is sufficient to use the class System.Threading.Interlocked , which ensures that the operations are atomic. In this case, no additional synchronization is required.
As an alternative to software synchronization at the client level, you can try to apply the transaction isolation mechanism provided at the server level. For example, if it is MS SQL Server, then it is enough to send a server ( dock ) to the server before starting the request:
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
After that, all requests will automatically become synchronized. I do not know whether this will be faster - this is a question. You can also play around with the isolation level of transactions - it can help.