{"id":18026801,"url":"https://github.com/yegor256/futex","last_synced_at":"2025-08-27T03:18:00.171Z","repository":{"id":48082068,"uuid":"154794146","full_name":"yegor256/futex","owner":"yegor256","description":"File-based Ruby Mutex","archived":false,"fork":false,"pushed_at":"2025-08-23T03:58:22.000Z","size":123,"stargazers_count":15,"open_issues_count":7,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-24T07:22:20.802Z","etag":null,"topics":["concurrency","entrance-lock","lock","locking","mutex","ruby","threads"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/futex","language":"Ruby","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/yegor256.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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,"zenodo":null}},"created_at":"2018-10-26T07:23:37.000Z","updated_at":"2025-08-17T10:45:25.000Z","dependencies_parsed_at":"2025-03-14T01:25:17.554Z","dependency_job_id":"517c3f23-9440-4074-a2e4-d234eee9e296","html_url":"https://github.com/yegor256/futex","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/yegor256/futex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yegor256%2Ffutex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yegor256%2Ffutex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yegor256%2Ffutex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yegor256%2Ffutex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yegor256","download_url":"https://codeload.github.com/yegor256/futex/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yegor256%2Ffutex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271876032,"owners_count":24837335,"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-08-24T02:00:11.135Z","response_time":111,"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":["concurrency","entrance-lock","lock","locking","mutex","ruby","threads"],"created_at":"2024-10-30T08:08:07.078Z","updated_at":"2025-08-27T03:18:00.162Z","avatar_url":"https://github.com/yegor256.png","language":"Ruby","readme":"\u003cimg src=\"/logo.svg\" width=\"64px\" height=\"64px\"/\u003e\n\n[![EO principles respected here](https://www.elegantobjects.org/badge.svg)](https://www.elegantobjects.org)\n[![DevOps By Rultor.com](https://www.rultor.com/b/yegor256/futex)](https://www.rultor.com/p/yegor256/futex)\n[![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)\n\n[![Build Status](https://travis-ci.org/yegor256/futex.svg)](https://travis-ci.org/yegor256/futex)\n[![Build status](https://ci.appveyor.com/api/projects/status/po1mn8ca96jk0llr?svg=true)](https://ci.appveyor.com/project/yegor256/futex)\n[![Gem Version](https://badge.fury.io/rb/futex.svg)](https://badge.fury.io/rb/futex)\n[![Maintainability](https://api.codeclimate.com/v1/badges/5528e182bb5e4a2ecc1f/maintainability)](https://codeclimate.com/github/yegor256/futex/maintainability)\n[![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://rubydoc.info/github/yegor256/futex/master/frames)\n\n[![Hits-of-Code](https://hitsofcode.com/github/yegor256/futex)](https://hitsofcode.com/view/github/yegor256/futex)\n[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/futex/blob/master/LICENSE.txt)\n\nSometimes you need to synchronize your block of code, but `Mutex` is too coarse-grained,\nbecause it _always locks_, no matter what objects your code accesses. The\n`Futex` (from \"file mutex\") is more fine-grained and uses a file as an\nentrance lock to your code.\n\nFirst, install it:\n\n```bash\n$ gem install futex\n```\n\nThen, use it like this:\n\n```ruby\nrequire 'futex'\nFutex.new('/tmp/my-file.txt').open do |f|\n  IO.write(f, 'Hello, world!')\nend\n```\n\nThe file `/tmp/my-file.txt.lock` will be created and used as an entrance lock.\nIt \u003cdel\u003ewill\u003c/del\u003e [won't](https://github.com/yegor256/futex/issues/5) be deleted afterwards.\n\nIf you are not planning to write to the file, it is recommended to get\na non-exclusive/shared access to it, by providing `false` to the method\n`open()`:\n\n```ruby\nrequire 'futex'\nFutex.new('/tmp/my-file.txt').open(false) do |f|\n  IO.read(f)\nend\n```\n\nFor better traceability you can provide a few arguments to the\nconstructor of the `Futex` class, including:\n\n  * `log`: an object that implements `debug()` method, which will\n    receive supplementary messages from the locking mechanism;\n\n  * `logging`: set it to `true` if you want to see logs;\n\n  * `timeout`: the number of seconds to wait for the lock availability\n    (`Futex::CantLock` exception is raised when the wait is expired);\n\n  * `sleep`: the number of seconds to wait between attempts to acquire\n    the lock file (the smaller the number, the more responsive is the software,\n    but the higher the load for the file system and the CPU);\n\n  * `lock`: the absolute path of the lock file;\n\nThat's it.\n\n## How to contribute\n\nRead [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).\nMake sure your build is green before you contribute\nyour pull request. You will need to have [Ruby](https://www.ruby-lang.org/en/) 2.3+ and\n[Bundler](https://bundler.io/) installed. Then:\n\n```\n$ bundle update\n$ bundle exec rake\n```\n\nIf it's clean and you don't see any error messages, submit your pull request.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyegor256%2Ffutex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyegor256%2Ffutex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyegor256%2Ffutex/lists"}