Giter VIP home page Giter VIP logo

deadlock-examples's Introduction

deadlock-examples

Deadlock examples

  1. MonitorAwait.
    Reentrant lock is not possible after await statement since the continuation may run in another thread so thread effectively locks. This is the reason why await is not permitted inside lock block. Solution: never use await between Monitor.Enter and Monitor.Exit.
  2. DoubleObjectLock
    The classic example of deadlock: both threads try to lock two different resources but in different order thus locking each other at last step. Solution: always take locks in the same order for all actors.
  3. DeadlockForm
    Gives an example of SynchronizationContext-related issues: explicit locking (call to Task.Result) makes UI thread irresponsive and prevents continuation from executing. Solution: never try to retrieve Result, use await.
  4. DbConcurrentUpdateLocks
    Two simultaneous transactions try to update the same rows but in reverse order (similar to p. 2), and one of them falls victim. Solution: always take locks in the same order for all actors.
  5. LockOnIndexKey
    The first transaction puts exclusive lock on one row and corresponding nonclustered index key. In several milliseconds Transaction 2 uses UPDLOCK hint in order to place update lock (obviously) on another row. Next command in Transaction 1 that is trying to access another row may never succeed thus deadlock. The problem here is that attempt to update different rows does not lock two transactions, but if the change is affecting indexed properties, there is possibility to get involved in fight over index keys. It's especially nasty when it happens in different order. Solution: if there is identical SQL for both transactions, for example, 1) SELECT(UPDLOCK) 2) UPDATE, then you can use SERIALIZABLE isolation level since it won't allow to place U locks on index pages affected. If you are dealing with the situation like the one in repo, I would go for sp_getapplock with custom sync object in order to forbid placing locks on nonclustered and clustered indexes altogether.
  6. SingleThreadDeadlock
    Thread tries to join itself so to end its execution it waits for the ending of its execution, purely fictional example

deadlock-examples's People

Contributors

yurasovdv avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.