Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V6129. Possible deadlock due to...
menu mobile close menu
Additional information
toggle menu Contents

V6129. Possible deadlock due to incorrect synchronization order between locks.

May 26 2025

The analyzer has detected a potential deadlock caused by a violation of the lock acquisition order across different methods. This happens when synchronized code blocks acquire object monitors in inconsistent sequences. When such methods run concurrently, two threads may wait indefinitely for each other while holding different locks.

The example:

void foo() {
    synchronized (lock1) {
        synchronized (lock2) {
            ....
        }
    }
}

void bar() {
    synchronized (lock2) {
        synchronized (lock1) {
            ....
        }
    }
}

If one thread starts executing foo() and acquires lock1 first, while another thread concurrently runs bar() and acquires lock2, the first thread will be blocked when attempting to acquire lock2, and the second thread will be blocked while waiting for lock1. A deadlock occurs because each thread is holding a resource that the other one needs, causing both to wait indefinitely unless externally interrupted.

The fixed code:

void foo() {
    synchronized (lock1) {
        synchronized (lock2) {
            ....
        }
    }
}

void bar() {
    synchronized (lock1) {
        synchronized (lock2) {
            ....
        }
    }
}

This diagnostic is classified as:

close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
close form
Free PVS‑Studio license for Microsoft MVP specialists
close form
To get the licence for your open-source project, please fill out this form
close form
I want to join the test
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam