@amiloradovsky If you figure out how to statically analyze whether or not a program with almost any amount of locking has deadlocks, you'll probably receive the CS world's highest achievement award. I would then recommend that you move on to statically analyzing whether or not a program halts. :)
There are really two ways to avoid deadlocks entirely AFAIK: no-shared-state-with-message-passing (actors, Erlang, E, Goblins/Goblinoid) and Rust's ownership model.