{"id":20923496,"url":"https://github.com/njaard/pond","last_synced_at":"2025-07-15T18:45:01.329Z","repository":{"id":57666408,"uuid":"111299579","full_name":"njaard/pond","owner":"njaard","description":"Rust: A scoped threadpool where each thread has a state","archived":false,"fork":false,"pushed_at":"2020-04-10T15:25:03.000Z","size":17,"stargazers_count":13,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-20T14:21:33.069Z","etag":null,"topics":["crates","rust","thread-pool"],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/njaard.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":"2017-11-19T13:50:58.000Z","updated_at":"2023-02-06T20:20:12.000Z","dependencies_parsed_at":"2022-09-26T20:31:46.374Z","dependency_job_id":null,"html_url":"https://github.com/njaard/pond","commit_stats":null,"previous_names":["njaard/scope-threadpool"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/njaard/pond","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/njaard%2Fpond","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/njaard%2Fpond/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/njaard%2Fpond/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/njaard%2Fpond/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/njaard","download_url":"https://codeload.github.com/njaard/pond/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/njaard%2Fpond/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265451621,"owners_count":23767794,"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":["crates","rust","thread-pool"],"created_at":"2024-11-18T20:16:06.882Z","updated_at":"2025-07-15T18:45:01.273Z","avatar_url":"https://github.com/njaard.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GitHub license](https://img.shields.io/badge/license-BSD-blue.svg)](https://raw.githubusercontent.com/njaard/pond/master/LICENSE)\n[![Crates.io](https://img.shields.io/crates/v/pond.svg)](https://crates.io/crates/pond)\n[![Documentation](https://docs.rs/pond/badge.svg)](https://docs.rs/pond/)\n\n\t[dependencies]\n\tpond = \"0.3\"\n\n# Introduction\nYet another implementation of a scoped threadpool.\n\nA scoped threadpool allows many tasks to be executed\nin the current function scope, which means that\ndata doesn't need to have a `'static` lifetime.\n\nThis one is has the additional ability to store a mutable\nstate in each thread, which permits you to, for example, reuse\nexpensive-to-setup database connections, one per thread. Also,\nyou can set a backlog which can prevent an explosion of memory\nusage if you have many jobs to start.\n\n# Usecase\nIf you need to make multiple connections to a database server,\nwithout this crate, you need some sort of connection pooling library,\nand therefor each connection needs Rust's `Send` capability. Furthermore,\nthere's no guarantee that your connection pooler will keep the\nconnection on the same thread.\n\nWith this crate, you provide a function that sets up the connection,\nthen the function is called in each thread at initialization time.\nA mutable reference is passed to your job closures. It's your\njob's responsibility to make sure that each job keep the database\nconnection in a sane state between jobs.\n\nUsing the state-making capability is optional. If you don't call the\n`with_state` function, then your job closures don't need any parameters,\nwhich therefor makes this crate compatible with other scoped threadpool\nlibraries.\n\n# Example\n    extern crate pond;\n    let mut pool = pond::Pool::new();\n\n    let mut vec = vec![0, 0, 0, 0, 0, 0, 0, 0];\n\n    // Each thread can access the variables from\n    // the current scope\n    pool.scoped(\n        |scoped|\n        {\n            let scoped = scoped.with_state(\n                || \"costly setup function\".len()\n            );\n            // each thread runs the above setup function\n\n            // Create references to each element in the vector ...\n            for e in \u0026mut vec\n            {\n                scoped.execute(\n                    move |state|\n                    {\n                        *e += *state;\n                        assert_eq!(*e, 21);\n                    }\n                );\n            }\n        }\n    );\n\n# Changelog\n\n* 0.3.0 (2018-07-09): The constructor for `Pool` now in general defaults\nto the native number of threads, and the backlog is no longer unbounded.\nI have found that this makes things less error prone and less unnecessarily\nverbose.\n\n# See Also\n\n* [scoped-threadpool](https://crates.io/crates/scoped-threadpool) (Original inspiration for this crate. Has a very similar API, but no state).\n* [scoped_pool](https://crates.io/crates/scoped_pool) (Very flexible, but no state)\n* [crossbeam](https://crates.io/crates/crossbeam) (doesn't implement a thread pool)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnjaard%2Fpond","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnjaard%2Fpond","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnjaard%2Fpond/lists"}