{"id":19659715,"url":"https://github.com/lrita/gosync","last_synced_at":"2025-04-28T20:31:57.145Z","repository":{"id":78945287,"uuid":"76032615","full_name":"lrita/gosync","owner":"lrita","description":"a TryLock implementation","archived":false,"fork":false,"pushed_at":"2018-05-07T07:35:58.000Z","size":5,"stargazers_count":16,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-05T10:51:08.627Z","etag":null,"topics":["go","golang","golang-package","mutex","trylock"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lrita.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2016-12-09T12:11:57.000Z","updated_at":"2024-05-27T08:57:52.000Z","dependencies_parsed_at":"2023-03-12T06:15:52.899Z","dependency_job_id":null,"html_url":"https://github.com/lrita/gosync","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lrita%2Fgosync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lrita%2Fgosync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lrita%2Fgosync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lrita%2Fgosync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lrita","download_url":"https://codeload.github.com/lrita/gosync/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251383830,"owners_count":21580945,"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":["go","golang","golang-package","mutex","trylock"],"created_at":"2024-11-11T15:44:12.024Z","updated_at":"2025-04-28T20:31:56.880Z","avatar_url":"https://github.com/lrita.png","language":"Go","readme":"# A mutex implementation with TryLock\n![gosync.svg](https://travis-ci.org/lrita/gosync.svg?branch=master)\n\n## safe guaranteed\nHere is a general situations:\n\n```\nmutex.Lock()\nA()                       mutex.Lock()\nmutex.UnLock()            B()\n                          mutex.UnLock()\n```\n\nWhen we synchronize using mutex, we should guarantee unlock() `happens before` lock()\nto make no data race.\n\n[_A send on a channel happens before the corresponding receive from that channel completes_](https://golang.org/ref/mem#tmp_7), \nso we use a buffered channel to guarantee this.\n\n## interface\n```\ntype Mutex interface {\n\tLock()\n\tUnLock()\n\t// TryLock return true if it fetch mutex\n\tTryLock() bool\n\t// TryLockTimeout return true if it fetch mutex, return false if timeout\n\tTryLockTimeout(timeout time.Duration) bool\n\t// TryLockTimeout return true if it fetch mutex, return false if context done\n\tTryLockContext(ctx context.Context) bool\n}\n\ntype MutexGroup interface {\n\tLock(i interface{})\n\tUnLock(i interface{})\n\t// TryLock return true if it fetch mutex\n\tTryLock(i interface{}) bool\n\t// TryLockTimeout return true if it fetch mutex, return false if timeout\n\tTryLockTimeout(i interface{}, timeout time.Duration) bool\n\t// TryLockTimeout return true if it fetch mutex, return false if context done\n\tTryLockContext(i interface{}, ctx context.Context) bool\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flrita%2Fgosync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flrita%2Fgosync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flrita%2Fgosync/lists"}