{"id":19208550,"url":"https://github.com/heiwa4126/goflock-ex1","last_synced_at":"2025-10-08T06:54:29.241Z","repository":{"id":57623967,"uuid":"397781560","full_name":"heiwa4126/goflock-ex1","owner":"heiwa4126","description":"GoLangで複数プロセスでflockを使って排他制御を行うサンプルコード","archived":false,"fork":false,"pushed_at":"2021-08-23T08:49:52.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-28T05:34:31.102Z","etag":null,"topics":["example","flock","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/heiwa4126.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-19T01:34:55.000Z","updated_at":"2021-08-23T05:34:30.000Z","dependencies_parsed_at":"2022-08-26T20:46:48.199Z","dependency_job_id":null,"html_url":"https://github.com/heiwa4126/goflock-ex1","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/heiwa4126/goflock-ex1","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiwa4126%2Fgoflock-ex1","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiwa4126%2Fgoflock-ex1/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiwa4126%2Fgoflock-ex1/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiwa4126%2Fgoflock-ex1/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heiwa4126","download_url":"https://codeload.github.com/heiwa4126/goflock-ex1/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiwa4126%2Fgoflock-ex1/sbom","scorecard":{"id":459894,"data":{"date":"2025-08-11","repo":{"name":"github.com/heiwa4126/goflock-ex1","commit":"d39b1819f9787b8e135ede3d09c8fc68e89732dd"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.5,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Code-Review","score":0,"reason":"Found 0/9 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":9,"reason":"1 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GO-2022-0493 / GHSA-p782-xgp4-8hr8"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T10:49:23.135Z","repository_id":57623967,"created_at":"2025-08-19T10:49:23.135Z","updated_at":"2025-08-19T10:49:23.135Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278903034,"owners_count":26065786,"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","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["example","flock","golang"],"created_at":"2024-11-09T13:26:59.185Z","updated_at":"2025-10-08T06:54:29.212Z","avatar_url":"https://github.com/heiwa4126.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# goflock-ex1\n\nGoLangで複数プロセスでflockを使って排他制御を行うサンプルコード。\nflock()を使っているのでUNIXのみ動く。詳しくは`man 2 flock`参照。\n\n[heiwa4126/python_flock_ex1: Python 3で複数プロセスでflockを使って排他制御を行うサンプルコード](https://github.com/heiwa4126/python_flock_ex1)\nがちょっとおもしろかったので、Go版を書いてみました。\n\n\n# 動かし方\n\nまずビルド\n```sh\ngo build\n```\n\nGoなのでサブコマンド式になってます。\n\n```sh\nBIN=./goflock-ex1\nINIT=\"$BIN init\"      # カウンターを0に初期化\nINC=\"$BIN inc\"        # カウンターを10000増やす(排他制御なし)。並行で複数動かすと死ぬ。\nFINC=\"$BIN flockinc\"  # カウンターを10000増やす。並行で動かしても死なない。\n\n# 期待通りに動いて、10000になる\n$INIT ; $INC\n\n# 死ぬ。または30000にならない\n$INIT ; $INC \u0026 $INC \u0026 $INC\n\n# 30000になる\n$INIT ; $FINC \u0026 $FINC \u0026 $FINC\n```\n\n# ex1,2 ...\n\n- ex1 - 素朴版。もとのPythonと同じ。ただしバッファリングなし。ファイルは数字文字列\n- ex2 - バッファリングなし。ファイルはUINT64をリトルエンディアンで\n- ex3 - 無理やりバッファI/Oにしてみた。ファイルはex2と同じ\n- ex4 - ex2を [gofrs/flock](https://github.com/gofrs/flock) にしてみたもの。ロックファイルがカウンタファイルと別\n\n\n# そのほかメモ\n\nPythonとちがって\nカウンターファイルをIOバッファリングしてないので、\nファイルそのものにロックがかけられる。\n\nまあ効率を考えるとファイルの規模が大きくなるとバッファ使わないわけにいかないので\nPython同様、別ロックファイルにするべきだろう。\n-\u003e それはどうだろうか。\n\nあと、Python版と等しくカウンターファイルを文字列にしてるんだけど\n効率よくないのでUINT64そのもの書く版も学習用に作ってみる。\n-\u003e ex2として作ってみました。\n\nRust版も作ってみるかなあ。\n\nUNIX以外もサポートする場合は\n[gofrs/flock: Thread\\-safe file locking library in Go \\(originally github\\.com/theckman/go\\-flock\\)](https://github.com/gofrs/flock)\nを参照。\n\n終わったら\n```sh\nrm /tmp/goflock-ex1-count*\n```\nすること。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheiwa4126%2Fgoflock-ex1","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheiwa4126%2Fgoflock-ex1","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheiwa4126%2Fgoflock-ex1/lists"}