{"id":26826734,"url":"https://github.com/hslam/sem","last_synced_at":"2025-04-28T17:01:26.024Z","repository":{"id":144227662,"uuid":"316716494","full_name":"hslam/sem","owner":"hslam","description":"Package sem provides a way to use System V semaphores.","archived":false,"fork":false,"pushed_at":"2021-01-16T18:52:31.000Z","size":16,"stargazers_count":6,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T11:32:46.526Z","etag":null,"topics":["go","golang","ipc","sem","semaphore","semget","system-v","unix"],"latest_commit_sha":null,"homepage":"","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/hslam.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":"2020-11-28T11:17:57.000Z","updated_at":"2024-05-30T20:18:37.000Z","dependencies_parsed_at":"2024-08-04T16:24:17.365Z","dependency_job_id":null,"html_url":"https://github.com/hslam/sem","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hslam%2Fsem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hslam%2Fsem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hslam%2Fsem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hslam%2Fsem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hslam","download_url":"https://codeload.github.com/hslam/sem/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251352207,"owners_count":21575858,"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","ipc","sem","semaphore","semget","system-v","unix"],"created_at":"2025-03-30T11:30:49.971Z","updated_at":"2025-04-28T17:01:25.967Z","avatar_url":"https://github.com/hslam.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sem\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/hslam/sem)](https://pkg.go.dev/github.com/hslam/sem)\n[![Build Status](https://github.com/hslam/sem/workflows/build/badge.svg)](https://github.com/hslam/sem/actions)\n[![Go Report Card](https://goreportcard.com/badge/github.com/hslam/sem)](https://goreportcard.com/report/github.com/hslam/sem)\n[![LICENSE](https://img.shields.io/github/license/hslam/sem.svg?style=flat-square)](https://github.com/hslam/sem/blob/master/LICENSE)\n\nPackage sem provides a way to use System V semaphores.\n\n## Get started\n\n### Install\n```\ngo get github.com/hslam/sem\n```\n### Import\n```\nimport \"github.com/hslam/sem\"\n```\n### Usage\n####  Example\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/hslam/ftok\"\n\t\"github.com/hslam/sem\"\n\t\"time\"\n)\n\nfunc main() {\n\tkey, err := ftok.Ftok(\"/tmp\", 0x22)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tnsems := 1\n\tsemid, err := sem.Get(key, nsems, 0666)\n\tif err != nil {\n\t\tsemid, err = sem.Get(key, nsems, sem.IPC_CREAT|sem.IPC_EXCL|0666)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\tdefer sem.Remove(semid)\n\t\tfor semnum := 0; semnum \u003c nsems; semnum++ {\n\t\t\t_, err := sem.SetValue(semid, semnum, 1)\n\t\t\tif err != nil {\n\t\t\t\tpanic(err)\n\t\t\t}\n\t\t}\n\t}\n\tsemnum := 0\n\tif count, err := sem.GetValue(semid, semnum); err != nil {\n\t\tpanic(err)\n\t} else if count == 0 {\n\t\tfmt.Printf(\"%s semnum %d wait\\n\", time.Now().Format(\"15:04:05\"), semnum)\n\t}\n\tok, err := sem.P(semid, semnum, sem.SEM_UNDO)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Printf(\"%s semnum %d P %t\\n\", time.Now().Format(\"15:04:05\"), semnum, ok)\n\ttime.Sleep(time.Second * 10)\n\tok, err = sem.V(semid, semnum, sem.SEM_UNDO)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Printf(\"%s semnum %d V %t\\n\", time.Now().Format(\"15:04:05\"), semnum, ok)\n\ttime.Sleep(time.Second * 20)\n}\n```\n\n#### Output\n\n```sh\n$ go run main.go\n12:35:21 semnum 0 P true\n12:35:31 semnum 0 V true\n```\nIn another terminal.\n```sh\n$ go run main.go\n12:35:25 semnum 0 wait\n12:35:31 semnum 0 P true\n12:35:41 semnum 0 V true\n```\n\n### License\nThis package is licensed under a MIT license (Copyright (c) 2020 Meng Huang)\n\n\n### Author\nsem was written by Meng Huang.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhslam%2Fsem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhslam%2Fsem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhslam%2Fsem/lists"}