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

  • Home
  • SEARCH
  • 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 362607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:15:47+00:00 2026-05-12T13:15:47+00:00

I was asked this question in a .net/C# interview: If we have two threads

  • 0

I was asked this question in a .net/C# interview:

If we have two threads T1 and T2. T1
acquires a lock on obj1 and then does
some processing and acquires a lock on
obj2. T2 acquires a lock on obj2 and
then does some processing and acquires
a lock on obj1. So, we can have a
deadlock. What is common technique
that we use in multithreading to avoid
this situation?

I answered saying that T1 and T2 should have some mechanism to communicate and we should do the coding in such a way that T2 starts doing its job only after T1 has signalled that it is done with its job. The interviewer asked me if I knew about transactions and how we can use it to encounter this deadlock situation.
I have some amount of multithreading experience on the UI side in winforms. But, I have never used transactions. Can some one tell me more about this or point me to a url/book,

  • 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-12T13:15:48+00:00Added an answer on May 12, 2026 at 1:15 pm

    One general approach to avoid deadlocks is to ensure your threads/processes acquire locks on resources in the same order. eg, T2 should lock obj1 first and then obj2 (the same as T1).

    That way you can’t have both threads holding a resource that the other thread wants, ie a deadlock.

    If the wording in your quote was the exact question, it is badly written. It should be:

    T1 acquires a lock on obj1, does
    something and then tries to also lock
    obj2 without unlocking obj1. At the same time T2 acquires
    a lock on obj2, does something and
    then tries to also lock obj1 without unlocking obj2. A
    deadlock will occur.

    I highly recommend reading Concurrent Programming on Windows by Joe Duffy. It’s probably the most comprehensive book on threading theory and practice for Windows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 295k
  • Answers 295k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Christopher, maybe using Timer and Event classes is more appropriate… May 13, 2026 at 6:54 pm
  • Editorial Team
    Editorial Team added an answer a character array is simply an array of characters a… May 13, 2026 at 6:54 pm
  • Editorial Team
    Editorial Team added an answer Have you reviewed PARSL? It's an XML based robotic scripting… May 13, 2026 at 6:54 pm

Related Questions

I posted this question: https://stackoverflow.com/questions/418597/java-and-net-for-php-programmer and the answers I was given didn't really help
I am using C#. I have created a class which can be included in
I also have a desktop application written in Windows Forms that is a middling
I understand that this is a very broad question, but a short it depends

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.