---
id: 1856
title: "How to check if a mutex is locked in Go"
source_domain: blog.trailofbits.com
source_url: "https://blog.trailofbits.com/2020/06/09/how-to-check-if-a-mutex-is-locked-in-go/"
published_at: "2020-06-09T11:50:53Z"
tags: ["go", "debugging", "concurrency", "golang", "reflection", "mutex", "sync", "sync-mutex", "assertions"]
phying_url: "https://phying.com/item/1856"
lang: en
---

# How to check if a mutex is locked in Go

## Summary

Go's sync.Mutex can't tell you if it's locked—a deliberate omission due to race conditions. Reflection on the internal state field enables debug-only assertions for mutex preconditions.

## Intelligence Metadata

- **Sources:** blog.trailofbits.com
- **Published:** 2020-06-09T11:50:53Z
- **Original:** https://blog.trailofbits.com/2020/06/09/how-to-check-if-a-mutex-is-locked-in-go/
- **Phying News:** https://phying.com/item/1856
