Are there any differences between Java's “synchronized” and C#'s “lock”?

前端 未结 3 1895
栀梦
栀梦 2020-12-10 13:01

Do these two keywords have exactly the same effect, or is there something I should be aware of?

3条回答
  •  忘掉有多难
    2020-12-10 13:39

    According to this site: http://en.csharp-online.net/CSharp_FAQ:_What_is_the_difference_between_CSharp_lock_and_Java_synchronized, C# lock and Java synchronized code blocks are "semantically identical", while for methods, Java uses synchronized while C# uses an attribute: [MethodImpl(MethodImplOptions.Synchronized)].

提交回复
热议问题