{"id":20961417,"url":"https://github.com/perbu/mutexdebug","last_synced_at":"2026-04-21T18:32:50.880Z","repository":{"id":178273960,"uuid":"661610340","full_name":"perbu/mutexdebug","owner":"perbu","description":null,"archived":false,"fork":false,"pushed_at":"2023-07-03T09:34:54.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-20T00:47:29.223Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/perbu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-03T08:58:26.000Z","updated_at":"2023-07-03T08:58:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"e280bb6b-4f5a-4098-bfe5-49ac5dbe2675","html_url":"https://github.com/perbu/mutexdebug","commit_stats":null,"previous_names":["perbu/mutexdebug"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perbu%2Fmutexdebug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perbu%2Fmutexdebug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perbu%2Fmutexdebug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perbu%2Fmutexdebug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/perbu","download_url":"https://codeload.github.com/perbu/mutexdebug/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243358212,"owners_count":20277991,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T02:04:05.258Z","updated_at":"2025-12-24T18:40:17.371Z","avatar_url":"https://github.com/perbu.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mutexdebug\n\nThis package provides a simple mutex implementation for debugging purposes.\nThe constructor takes a timeout parameter, which is the maximum time a mutex\ncan be locked before it is considered to be locked forever. This is useful\nfor debugging deadlocks.\n\nIt has a significant performance impact, so it should not be used in production.\n\n\n## Usage\n\nFirst you need to create an interface that will allow you to easily switch\nbetween the real mutex and the debug mutex. This is done by creating a\n`MutexInterface`:\n\n```go\npackage mypackage\ntype MutexInterface interface {\n    Lock()\n    Unlock()\n}\n```\n\nNow you can initialize the mutex in your code:\n\n```go\npackage main\n\nfunc useMutex() {\n\tvar m MutexInterface\n\tswitch debug {\n\tcase true:\n\t\tm = mutexdebug.NewDebugMutex(time.Millisecond*40, true)\n\tdefault:\n\t\tm = \u0026sync.Mutex{}\n\t}\n\t// now we use the mutex as usual.\n\tm.Lock()\n\t// do something\n\tm.Unlock()\n\t\n\t// you should be able to cast the mutex back to the debug mutex\n\t// then you can access the debug information, like the number of warnings issued.\n\t// see the tests for more information.\n\t\n}\n\n```\n## Complete example\nNow you use the interface instead of the real mutex in your code and you can switch between the two.\n\n```go\npackage main\n\nimport (\n\t\"github.com/perbu/mutexdebug\"\n\t\"time\"\n)\n\ntype MutexInterface interface {\n\tLock()\n\tUnlock()\n}\n\nconst debug = true\n\nfunc main() {\n\tvar m MutexInterface\n\tswitch debug {\n\tcase true:\n\t\tm = mutexdebug.NewDebugMutex(time.Millisecond * 40, true)\n    default:\n\t\tm = \u0026sync.Mutex{}\n\t}\n\t// now we use the mutex as usual.\n\tm.Lock()\n\t// do something\n\tm.Unlock()\n    if debug {\n        dm := m.(*mutexdebug.DebugMutex)\n        fmt.Println(\"Number of mutexes held too long: \",dm.Warnings.Load())\n    }\n\t\n}\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperbu%2Fmutexdebug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperbu%2Fmutexdebug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperbu%2Fmutexdebug/lists"}