{"id":935,"url":"https://github.com/nvzqz/Threadly","last_synced_at":"2025-07-30T19:33:08.993Z","repository":{"id":45810431,"uuid":"95052709","full_name":"nvzqz/Threadly","owner":"nvzqz","description":"Type-safe thread-local storage in Swift","archived":false,"fork":false,"pushed_at":"2018-11-06T21:01:52.000Z","size":733,"stargazers_count":72,"open_issues_count":3,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-05-29T08:16:22.240Z","etag":null,"topics":["carthage","cocoapods","concurrency","ios","linux","macos","swift","thread","tvos","type-safety"],"latest_commit_sha":null,"homepage":"https://nvzqz.github.io/Threadly/docs/","language":"Swift","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/nvzqz.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}},"created_at":"2017-06-21T22:46:59.000Z","updated_at":"2023-12-13T13:52:08.000Z","dependencies_parsed_at":"2022-09-22T14:41:16.101Z","dependency_job_id":null,"html_url":"https://github.com/nvzqz/Threadly","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nvzqz%2FThreadly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nvzqz%2FThreadly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nvzqz%2FThreadly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nvzqz%2FThreadly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nvzqz","download_url":"https://codeload.github.com/nvzqz/Threadly/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228179035,"owners_count":17881126,"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":["carthage","cocoapods","concurrency","ios","linux","macos","swift","thread","tvos","type-safety"],"created_at":"2024-01-05T20:15:34.986Z","updated_at":"2024-12-04T19:32:25.651Z","avatar_url":"https://github.com/nvzqz.png","language":"Swift","readme":"[![Threadly](https://github.com/nvzqz/Threadly/raw/assets/banner.png)](https://github.com/nvzqz/Threadly)\n\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/platform-ios%20%7C%20macos%20%7C%20watchos%20%7C%20tvos%20%7C%20linux-lightgrey.svg\" alt=\"Platform\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/language-swift-orange.svg\" alt=\"Language: Swift\"\u003e\n    \u003cimg src=\"https://img.shields.io/cocoapods/dt/Threadly.svg\" alt=\"downloads\"\u003e\n    \u003cbr\u003e\n    \u003ca href=\"https://cocoapods.org/pods/Threadly\"\u003e\u003cimg src=\"https://img.shields.io/cocoapods/v/Threadly.svg\" alt=\"CocoaPods - Threadly\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/Carthage/Carthage\"\u003e\u003cimg src=\"https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat\" alt=\"Carthage\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://codebeat.co/projects/github-com-nvzqz-threadly-master\"\u003e\u003cimg src=\"https://codebeat.co/badges/5959731f-3832-4dbd-8c68-755a6071622b\" alt=\"codebeat badge\"\u003e\u003c/a\u003e\n    \u003cimg src=\"https://img.shields.io/badge/license-MIT-000000.svg\" alt=\"License\"\u003e\n    \u003cbr\u003e\n    \u003ca href=\"https://www.patreon.com/nvzqz\"\u003e\n        \u003cimg src=\"https://c5.patreon.com/external/logo/become_a_patron_button.png\" alt=\"Become a Patron!\" height=\"35\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://www.paypal.me/nvzqz\"\u003e\n        \u003cimg src=\"https://buymecoffee.intm.org/img/button-paypal-white.png\" alt=\"Buy me a coffee\" height=\"35\"\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\nThreadly is a Swift µframework that allows for type-safe thread-local storage.\n\n## What is [Thread-Local Storage](https://en.wikipedia.org/wiki/Thread-local_storage)?\n\n_Thread-local storage_ (TLS) lets you define a single variable that each thread\nhas its own separate copy of. This is great for cases such as having a mutable\nglobal variable that can't be safely accessed by multiple threads.\n\nOne example of this is with random number generators. Each thread can have its\nown seeded generator that's mutated on a per-thread basis. While this may\npotentially use more memory, it's much faster than accessing a shared global\nvariable through a mutex.\n\n## Build Status\n\n| Branch    | Status |\n| :-------: | :----: |\n| `master`  | [![Build Status](https://travis-ci.org/nvzqz/Threadly.svg?branch=master)](https://travis-ci.org/nvzqz/Threadly)\n\n## Installation\n\n### Compatibility\n\n- Platforms:\n    - macOS 10.9+\n    - iOS 8.0+\n    - watchOS 2.0+\n    - tvOS 9.0+\n    - Linux\n- Xcode 8.0+\n- Swift 3.0+\n\n### Install Using Swift Package Manager\nThe [Swift Package Manager](https://swift.org/package-manager/) is a\ndecentralized dependency manager for Swift.\n\n1. Add the project to your `Package.swift`.\n\n    ```swift\n    import PackageDescription\n\n    let package = Package(\n        name: \"MyAwesomeProject\",\n        dependencies: [\n            .Package(url: \"https://github.com/nvzqz/Threadly.git\",\n                     majorVersion: 1)\n        ]\n    )\n    ```\n\n2. Import the Threadly module.\n\n    ```swift\n    import Threadly\n    ```\n\n### Install Using CocoaPods\n[CocoaPods](https://cocoapods.org/) is a centralized dependency manager for\nObjective-C and Swift. Go [here](https://guides.cocoapods.org/using/index.html)\nto learn more.\n\n1. Add the project to your [Podfile](https://guides.cocoapods.org/using/the-podfile.html).\n\n    ```ruby\n    use_frameworks!\n\n    pod 'Threadly', '~\u003e 2.0.1'\n    ```\n\n    If you want to be on the bleeding edge, replace the last line with:\n\n    ```ruby\n    pod 'Threadly', :git =\u003e 'https://github.com/nvzqz/Threadly.git'\n    ```\n\n2. Run `pod install` and open the `.xcworkspace` file to launch Xcode.\n\n3. Import the Threadly framework.\n\n    ```swift\n    import Threadly\n    ```\n\n### Install Using Carthage\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency\nmanager for Objective-C and Swift.\n\n1. Add the project to your [Cartfile](https://github.com/Carthage/Carthage/blob/master/Documentation/Artifacts.md#cartfile).\n\n    ```\n    github \"nvzqz/Threadly\"\n    ```\n\n2. Run `carthage update` and follow [the additional steps](https://github.com/Carthage/Carthage#getting-started)\n   in order to add Threadly to your project.\n\n3. Import the Threadly framework.\n\n    ```swift\n    import Threadly\n    ```\n\n### Install Manually\n\nSimply add `Threadly.swift` into your project.\n\n## Usage\n\nTry it out for yourself! Download the repo and open 'Threadly.playground'.\n\n### Initialization\n\nThere are two ways to initialize a thread-local value. The value can be\ninitialized lazily when retrieved (`init(value:)` \u0026 `init(create:)`) or at the\ncall site (`init(capturing:)`).\n\nUsing `init(value:)` is an `@autoclosure` shorthand for `init(create:)`. This\nmeans that the thread-local value is initialized once per thread.\n\n```swift\nimport Foundation\n\nlet array = ThreadLocal(value: [1, 2, 3])\n\nThread.detachNewThread {\n    // Allocates an array with 3 elements for this thread\n    let arr = array.inner.value\n    doStuff(with: arr)\n}\n\n// Allocates another array of 3 elements for the main thread\ndoStuff(with: array.inner.value)\n```\n\nWhen using `init(capturing:)`, the thread-local value is initialized at the call\nsite.\n\n```swift\nimport Foundation\n\n// The inner value gets allocated\nlet array = ThreadLocal(capturing: [1, 2, 3])\n\nThread.detachNewThread {\n    // Retrieves a shallow copy of the initial value that can be used in this\n    // thread. If the thread-local value gets mutated, a deep copy occurs to\n    // retain value semantics.\n    let arr = array.inner.value\n    doStuff(with: arr)\n}\n\n// Same as the other thread, but now in the main thread\ndoStuff(with: array.inner.value)\n```\n\n### Exclusivity\n\nEach thread has exclusive access to its own local variable.\n\n```swift\nimport Foundation\n\nlet num = ThreadLocal(value: 42)\n\nThread.detachNewThread {\n    withUnsafePointer(to: \u0026num.inner.value) { ptr in\n        print(ptr) // 0x00007fa6f86074a0\n    }\n}\n\nwithUnsafePointer(to: \u0026num.inner.value) { ptr in\n    print(ptr) // 0x00007fa6f844c920\n}\n```\n\n## License\n\nAll source code for Threadly is released under the [MIT License][mit-license].\n\nAssets for Threadly are released under the [Creative Commons Attribution-ShareAlike 4.0 International License][cc-license]\nand can be found in the [`assets` branch](https://github.com/nvzqz/Threadly/tree/assets).\n\n[mit-license]: https://github.com/nvzqz/Threadly/blob/master/LICENSE.md\n[cc-license]: https://github.com/nvzqz/Threadly/blob/assets/LICENSE.txt\n","funding_links":["https://www.patreon.com/nvzqz","https://www.paypal.me/nvzqz"],"categories":["Concurrency","Storage"],"sub_categories":["Linter","Other free courses"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnvzqz%2FThreadly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnvzqz%2FThreadly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnvzqz%2FThreadly/lists"}