{"id":20231009,"url":"https://github.com/bewaremypower/cxxpthread","last_synced_at":"2026-06-12T09:32:03.681Z","repository":{"id":109020170,"uuid":"158398235","full_name":"BewareMyPower/cxxpthread","owner":"BewareMyPower","description":null,"archived":false,"fork":false,"pushed_at":"2019-01-08T16:02:27.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-03T13:45:39.937Z","etag":null,"topics":["cpp11","pthreads-wrapper","thread"],"latest_commit_sha":null,"homepage":null,"language":"C++","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/BewareMyPower.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-20T14:00:09.000Z","updated_at":"2019-01-08T16:02:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"92f260f2-8e48-45a4-a07f-4c19d3838cf2","html_url":"https://github.com/BewareMyPower/cxxpthread","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/BewareMyPower/cxxpthread","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BewareMyPower%2Fcxxpthread","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BewareMyPower%2Fcxxpthread/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BewareMyPower%2Fcxxpthread/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BewareMyPower%2Fcxxpthread/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BewareMyPower","download_url":"https://codeload.github.com/BewareMyPower/cxxpthread/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BewareMyPower%2Fcxxpthread/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34238713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-12T02:00:06.859Z","response_time":109,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cpp11","pthreads-wrapper","thread"],"created_at":"2024-11-14T07:44:50.908Z","updated_at":"2026-06-12T09:32:03.658Z","avatar_url":"https://github.com/BewareMyPower.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cxxpthread\nA C++11 wrapper of pthread library, inspired by c++11 `\u003cthread\u003e`.\n\nIt's a header-only library, and only requires compiler which supports C++11. (eg. gcc 4.8)\n\nSee examples in [test](./test) to learn how it works.\nHere we'll give some simple examples, use `cxxpthread::Thread` need 2 or 3 steps:\n- 1. create\n- 2. join\n- 3. getResult() or getExitCode()\n\n# 1. Create thread\n## 1.1 from C-style functions\n```\nvoid f(int, int\u0026);\nint i, j;\n\nThread t(f, i, std::ref(j));\n```\n\n## 1.2 from function object\n```\nstruct Foo {\n  void operator(int, int\u0026);\n};\nFoo foo;\nint i, j;\n\nThread t(foo, i, std::ref(j));\n// NOTE: pass foo to Thread constructor means pass a copy of foo\n```\n\n## 1.3 from class member function\n```\nstruct Foo {\n  void f(int, int\u0026);\n};\nFoo foo;\nint i, j;\n\nThread t(\u0026Foo::f, \u0026foo, i, std::ref(j));\n```\n\n# 2. Join thread\nAfter `Thread` object `t` was created, you must call `t.join()` later, which internally calls `pthread_join()` and save result of `pthread_exit`.\n\n# 3. Get result of thread function\nThis step is not necessary, but if you want to get return value or exit code of thread function, you need it.\n## 3.1 Return value of thread function\n```\nint f() { return 100; }\n\nThread t(f);\nt.join();\nauto p = t.getResult\u003cint\u003e(t);  // p is std::unique_ptr\u003cint\u003e object\n```\n**NOTE**\n1. If you don't call `Thread::getResult\u003cT\u003e()` for a function with return value, it will cause memory leak!\n2. `Thread::getResult\u003cT\u003e()` can only be called once!\n3. If `T` is not proper, it may cause memory leak, like `int* p = new int(1); delete (double*)p; `;\n4. `T` must be moveable.\n\n## 3.2 Call `Thread::exit()` in thread function and get thread exit code by `Thread::getExitCode`\n```\nvoid f() { Thread::exit(1); }\n\nThread t(f);\nt.join();\nlong exit_code = t.getExitCode();  // 1\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbewaremypower%2Fcxxpthread","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbewaremypower%2Fcxxpthread","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbewaremypower%2Fcxxpthread/lists"}