How to lock on an integer in C#?

后端 未结 14 2217
醉梦人生
醉梦人生 2020-12-05 14:44

Is there any way to lock on an integer in C#? Integers can not be used with lock because they are boxed (and lock only locks on references).

The scenario is as follo

14条回答
  •  萌比男神i
    2020-12-05 15:02

    I doubt you should use a database or O/S level feature such as locks for a business level decision. Locks incur significant overheads when held for long times (and in these contexts, anything beyond a couple of hundred milliseconds is an eternity).

    Add a status field to the post. If you deal with several therads directly, then you can use O/S level locks -- to set the flag.

提交回复
热议问题