如何在 Go 中检查互斥锁是否被锁定
blog.trailofbits.com | 博客 | #go | #debugging | #concurrency | #golang | #reflection | #mutex | #sync | #sync-mutex | #assertions
摘要
Go 的 sync.Mutex 无法查询是否处于锁定状态——这是出于竞态考虑的有意省略。通过反射读取内部 state 字段,可实现仅在 debug 构建启用的互斥锁前置条件断言。
- 发布时间
- 收录时间
Skip to content