{"id":23091555,"url":"https://github.com/chopinsky/thread_pool","last_synced_at":"2025-08-16T09:30:30.393Z","repository":{"id":57669713,"uuid":"126120241","full_name":"Chopinsky/thread_pool","owner":"Chopinsky","description":"A Cargo package that can make you run your applications in thread-safe pools without efforts.","archived":false,"fork":false,"pushed_at":"2020-07-11T23:50:31.000Z","size":366,"stargazers_count":7,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-19T19:56:51.231Z","etag":null,"topics":[],"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/Chopinsky.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":"2018-03-21T03:50:29.000Z","updated_at":"2024-06-30T11:18:46.000Z","dependencies_parsed_at":"2022-09-26T20:40:34.352Z","dependency_job_id":null,"html_url":"https://github.com/Chopinsky/thread_pool","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chopinsky%2Fthread_pool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chopinsky%2Fthread_pool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chopinsky%2Fthread_pool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chopinsky%2Fthread_pool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Chopinsky","download_url":"https://codeload.github.com/Chopinsky/thread_pool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230026316,"owners_count":18161593,"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-12-16T21:18:38.450Z","updated_at":"2024-12-16T21:18:38.527Z","avatar_url":"https://github.com/Chopinsky.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Threads Pool\n\nThis package provides an easy way to create and manage thread pools, so you don't have to. \n\n## How to use\nIn your project's `Cargo.toml`, add dependency:\n```cargo\n[dependencies]\nthreads_pool = \"^0.2.0\"\n```\n\nThen in your code: \n```rust\nextern crate threads_pool;\n\nuse std::time::Duration;\nuse std::thread::sleep;\nuse threads_pool::*;\n\nfn main() {\n    // The pool lives as long as the `pool` variable, when pool goes out of \n    // the scope, the thread pool will be destroyed gracefully -- all threads \n    // will finish their current job and then garnered.   \n    let pool = ThreadPool::new(8);\n    \n    for num in 0..100 {\n        pool.execute(move || {\n            // Your code here...\n            println!(\"I'm in with: {}\", num);\n            sleep(Duration::from_millis(10));    \n        });\n    }\n}\n```\n\nThe package also provide a static pool which you can create once, and use it everywhere in your application. \nThis is called the `shared_mode`: \n```rust\nextern crate threads_pool;\n\nuse std::time::Duration;\nuse std::thread::sleep;\nuse threads_pool::shared_mode;\n\nfn main() {\n    // Create the pool here, then you can use the pool everywhere. If run a task without \n    // creating the pool, it will be equivalent of calling 'thread::spawn' on the task.\n    shared_mode::initialize(8);\n\n    for num in 0..100 {\n        shared_mode::run(move || {\n            // Your code here...\n            println!(\"I'm in with: {}\", num);\n            sleep(Duration::from_millis(10));\n        });\n    }\n\n    // The static pool must be closed, or unfinished threads will be destroyed prematurely and could cause panic in the\n    // running threads. this is different from the managed pool where it can know when to shutdown as the allocated pool\n    // object goes out of the scope.\n    shared_mode::close();\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchopinsky%2Fthread_pool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchopinsky%2Fthread_pool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchopinsky%2Fthread_pool/lists"}