The simple way to avoid deadlocks

A deadlock happens when there’s at least one resource that can be only acquired by one process at a time and there’s a process P1 that is waiting to acquire a resource currently held by a process P2 and P2 is waiting to acquire a resource currently held by P1. The word process does not mean we are talking about just OS processes. There are two processes: Process A wants to acquire a lock on resource 1 and then a lock on resource 2. Process B wants to acquire a lock on resource 2 and then a lock on resource 1. ...

March 25, 2023 · 2 min · poorlydefinedbehaviour

Database anomalies and isolation levels

Anomalies An anomaly or read phenomena can happen when a transaction reads data that may have been modified by another concurrent transaction. Dirty read A dirty read happens when a transaction T1 reads data that has been modified by a concurrent transaction T2 that has not has been committed or rolled back yet. T1 ends up working with stale data if T2 does not commit. T2 starts executing and sets x to a new value, T1 starts executing and reads x, the value of x is the value just set by T2, T2 rolls back, the value of x is not persisted to the database but T1 will move forward with the stale value of x that was written before T2 rolled back. ...

March 24, 2023 · 4 min · poorlydefinedbehaviour