{"id":19315999,"url":"https://github.com/socketry/thread-local","last_synced_at":"2025-05-08T19:30:07.734Z","repository":{"id":56896997,"uuid":"242292693","full_name":"socketry/thread-local","owner":"socketry","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-03T22:25:47.000Z","size":353,"stargazers_count":14,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-08T05:35:58.877Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/socketry.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":"2020-02-22T06:35:41.000Z","updated_at":"2024-04-17T07:34:28.000Z","dependencies_parsed_at":"2024-06-19T22:59:54.755Z","dependency_job_id":null,"html_url":"https://github.com/socketry/thread-local","commit_stats":{"total_commits":18,"total_committers":1,"mean_commits":18.0,"dds":0.0,"last_synced_commit":"aabb9b106bd03a4cc2cfc97732aa71b495e8536a"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketry%2Fthread-local","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketry%2Fthread-local/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketry%2Fthread-local/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketry%2Fthread-local/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/socketry","download_url":"https://codeload.github.com/socketry/thread-local/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253135140,"owners_count":21859571,"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-10T01:09:20.967Z","updated_at":"2025-05-08T19:30:07.711Z","avatar_url":"https://github.com/socketry.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Thread::Local\n\nProvides a simple high level interface for per-class thread locals. Implements a standard interface for \"shared global state\". Avoid reinventing thread-local semantics in your own code by using this implementation.\n\n[![Development Status](https://github.com/socketry/thread-local/workflows/Test/badge.svg)](https://github.com/socketry/thread-local/actions?workflow=Test)\n\n## Features\n\n  - Convert global state to thread local state easily.\n  - Avoid race conditions and data corruption.\n  - Provides a standard interface for policy driven design.\n\n## Motivation\n\nIn my own web framework, [utopia](https://github.com/socketry/utopia), I have been struggling with the best way to expose configuration details. I was setting both global variables and modifying `ENV` which made it impossible to have multiple isolated instances of the application in the same process. This in turn makes it hard to implement things like graceful restart in multi-threaded [falcon](https://github.com/socketry/falcon). Such issues also affect application code running in other multi-threaded contexts, which are becoming increasingly common (e.g. JRuby, TruffleRuby).\n\nGlobal variables are often not thread-safe and encourage poor programming style. In many cases it is desirable to have thread-local state, but implementing this directly in Ruby is unpleasant. This gem provides a best-practice wrapper which can extend existing classes to provide per-thread instances.\n\nConceptually, a thread is a container for application state. This works well when servers consider applications to be isolated on a per-thread basis, but this isn't always the case:\n\n| Server               | Application      | Thread Safety            |\n|----------------------|------------------|--------------------------|\n| Falcon Multi-Process | One per process. | Isolated.                |\n| Falcon Multi-Thread  | One per thread.  | Isolated, Shared State.  |\n| Puma Multi-Thread    | One per process. | Reentrant, Shared State. |\n| Puma Cluster         | One per worker.  | Reentrant, Shared State. |\n| Unicorn              | One per process. | Isolated.                |\n\nPuma requires applications to be completely thread safe and reentrant, which isn't always easy. However, this gem attempts to provide a model which works in all the above servers, providing isolated, thread-safe, mutable per-thread state.\n\n## Usage\n\nPlease see the [project documentation](https://socketry.github.io/thread-local).\n\n## Contributing\n\nWe welcome contributions to this project.\n\n1.  Fork it.\n2.  Create your feature branch (`git checkout -b my-new-feature`).\n3.  Commit your changes (`git commit -am 'Add some feature'`).\n4.  Push to the branch (`git push origin my-new-feature`).\n5.  Create new Pull Request.\n\n## See Also\n\n  - [fiber-local](https://github.com/socketry/fiber-local) — Allow per-fiber overrides to thread-local variables.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocketry%2Fthread-local","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsocketry%2Fthread-local","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocketry%2Fthread-local/lists"}