Skip to main content

What Is a Mutex Lock and How Is It an Alternative Reentrancy Prevention Mechanism?

A mutex (mutual exclusion) lock is a mechanism that prevents a function from being called again while it is already executing. In Solidity, this is typically implemented using a state variable (a boolean or an integer) that acts as a lock.

The function sets the lock at the beginning (Check), performs its logic and external call (Interaction), and then releases the lock at the end (Effect). The function checks the lock status at the start, reverting if it's already locked.

Do Reentrancy Guards Protect against Both Single-Function and Cross-Function Attacks?
Why Is Updating State before an External Call the Critical Part of the CEI Pattern?
What Are the Differences between Single-Function and Cross-Function Reentrancy Attacks?
How Does a Storage Variable Update Relate to the “Effects” Stage of the CEI Pattern?