{"id":21270652,"url":"https://github.com/timstr/threadpool","last_synced_at":"2025-03-15T12:12:18.619Z","repository":{"id":190845848,"uuid":"683459508","full_name":"timstr/threadpool","owner":"timstr","description":"A rust threadpool with parallel work-stealing \"foreach\" with non-static lifetime support","archived":false,"fork":false,"pushed_at":"2023-12-21T06:30:23.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-22T02:31:21.265Z","etag":null,"topics":["multithreading","parallel","rust","threading","work-stealing"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/timstr.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}},"created_at":"2023-08-26T16:35:27.000Z","updated_at":"2023-08-26T17:36:37.000Z","dependencies_parsed_at":"2024-01-15T17:40:19.088Z","dependency_job_id":null,"html_url":"https://github.com/timstr/threadpool","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"84e3cd3c4b4bc30881dc4df70192293f01ce9f9b"},"previous_names":["timstr/threadpool"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timstr%2Fthreadpool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timstr%2Fthreadpool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timstr%2Fthreadpool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timstr%2Fthreadpool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timstr","download_url":"https://codeload.github.com/timstr/threadpool/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243725636,"owners_count":20337670,"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":["multithreading","parallel","rust","threading","work-stealing"],"created_at":"2024-11-21T08:18:12.092Z","updated_at":"2025-03-15T12:12:18.599Z","avatar_url":"https://github.com/timstr.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# threadpool\n\nA basic threadpool that uses work-stealing and allows closures with non-static references.\n\nCurrently only `foreach` is implemented. This function takes a mutable slice and closure which mutates an element of the slice, and dispatches this to each thread in the pool on a first-come-first-serve basis. `foreach` returns once all elements in the slice have been visited.\n\nExample usage:\n\n```rust\nlet mut data: Vec\u003cusize\u003e = (0..65536).collect();\n\nlet mut threadpool = ThreadPool::new(1);\n\nlet offset: usize = 10;\n\nthreadpool.foreach(\u0026mut data, |x| {\n    *x = *x + offset; // \u003c---------- 'offset' is borrowed from multiple threads here!\n});\n\nassert!(data.iter().enumerate().all(|(i, x)| *x == i + 10));\n```\n\n## Is this library safe and sound?\n\nUm, probably? Thread-safe atomics, channels, and barriers are used to handle all synchronization and the included tests run and pass. However, I don't have a rigorous proof that it is guaranteed to be memory safe, and part of the implementation relies on `std::mem::transmute` to cast away the lifetime bound on the closure being passed to other threads. This is a known-workaround for writing threading primitives as mentioned in item 3 of https://github.com/rust-lang/rust/pull/55043. The use of a shared one-off barrier inside of `foreach` serves to ensure that all threads have finished using and dropped the closure before `foreach` returns.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimstr%2Fthreadpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimstr%2Fthreadpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimstr%2Fthreadpool/lists"}