Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6829741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:32:08+00:00 2026-05-26T22:32:08+00:00

What is the difference between locking on a type of a class vs locking

  • 0

What is the difference between locking on a type of a class vs locking on the class itself?

For example:

private readonly object xmpp = new object();

lock (xmpp)
{
    ...
}

vs

lock (typeof(Xmpp))
{
    ...
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:32:09+00:00Added an answer on May 26, 2026 at 10:32 pm
    • lock(x) synchronizes on a different lock for each instance of the type

    • lock(typeof(X)) synchronizes on the same lock for all instances of the type

    Always lock on a private lock object:

     public class X
     {
          private readonly Object _lock = new Object();
    
          // ...
                lock (_lock)
                {
                }
    

    If you must synchronize access to class static members, use the same pattern:

     public class X
     {
          private readonly static Object s_lock = new Object();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the difference between true type and open type font? Does the latter
What is the difference between using: $.ajax({ type: 'POST', url: Drupal.settings.basePath + 'module/get/' +
I understand the differences between optimistic and pessimistic locking. Now, could someone explain to
I was looking at Stack Overflow question What is the difference between abstract function
I'm looking for a way to determine the difference between two dates. A normal
I'm looking for a way to find the number of hours of difference between
I'm just looking for a simple, concise explanation of the difference between these two.
Ok so got through my last problem with the difference between Postgresql and SQLite
I'm not in a position to make out the difference between vld4_f32 and vld4q_f32
The latest C++ 11 specification defines a new type of for loop called range-based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.