Is using an existing object rather than creating a specific lock object safe?

后端 未结 2 1064
轻奢々
轻奢々 2021-01-14 16:26

EDIT: As it turns out when I was browsing I found a question the appears to be the same as mine which I didn\'t find earlier: Difference between lock(locker) and lock(variab

2条回答
  •  深忆病人
    2021-01-14 16:51

    You've pretty much answered your own question. For locking, it's generally better to create an object specifically for the purpose, and usually held privately for use by accessor methods that express synchronisation logic at a high level.

提交回复
热议问题