{"id":19602584,"url":"https://github.com/wang-bin/threadlocal","last_synced_at":"2025-07-24T16:40:22.141Z","repository":{"id":141348971,"uuid":"65113451","full_name":"wang-bin/ThreadLocal","owner":"wang-bin","description":"portable and implemention configurable c++11 like thread local","archived":false,"fork":false,"pushed_at":"2021-07-07T13:06:53.000Z","size":27,"stargazers_count":25,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-14T09:43:24.765Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wang-bin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2016-08-07T03:21:16.000Z","updated_at":"2024-11-11T18:05:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"6c8bd34a-61aa-4173-942e-c22bc9c400c0","html_url":"https://github.com/wang-bin/ThreadLocal","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/wang-bin%2FThreadLocal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wang-bin%2FThreadLocal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wang-bin%2FThreadLocal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wang-bin%2FThreadLocal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wang-bin","download_url":"https://codeload.github.com/wang-bin/ThreadLocal/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235208988,"owners_count":18953003,"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-11-11T09:24:58.037Z","updated_at":"2025-01-23T00:51:41.469Z","avatar_url":"https://github.com/wang-bin.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ThreadLocal\nPortable, implementation configurable and `c++11` thread_local compatible. The same code using macro `THREADL_LOCA(T)` supports different implementations controlled by macro `USE_STD_THREAD_LOCAL`.\n\nThe default implementation of macro `THREAD_LOCAL(...)` is c++11 `thread_local` keyword if supported. Otherwise, pthread and FLS implementation is used.\n\n## WHY\n- `c++11` **thread_local** is not available for vs2013, macOS\u003c10.10 and iOS, libc++ \u003c 4.0(android ndk \u003c r14), and non-trivial TLS destruction is not supported by MinGW clang.\n- std thread_local may have bugs, including mingw and android, see android-ndk/ndk issue 687\n\n## Limitation\nVariables declared by `THREAD_LOCAL(T)`(actually only `ThreadLocal\u003cT\u003e`) must have static storage duration, i.e. usually `static` specifier is required.\n\n## Examples\n\n```\n    // declare and initialize. use THREAD_LOCAL macro to switch between c++11 thread_local keyword and ThreadLocal\u003cT\u003e implementation at build time using -DUSE_STD_THREAD_LOCAL=1/0\n    static THREAD_LOCAL(int) a;\n    static THREAD_LOCAL(int) b(1);\n    static THREAD_LOCAL(int) c = 2;\n    // assignment\n    a = 3;\n    // get address of stored thread data\n    int* pa = \u0026a;\n    *pa = 4;\n    // type convert\n    printf(\"a=%d\\n\", (int\u0026)a);\n```\n\n## Tested Compilers\nVS\u003e=2013, gcc\u003e=4.7, clang \u003e=3.2, Apple clang, zpacc++1.0, icc\u003e=16\n\n## Build\n\n- `g++/clang++` `c++11` thread_local: `(clan)g++ -std=c++11 test.cpp`\n- `g++/clang++` pthread implementation: `(clan)g++ -std=c++11 test.cpp -DUSE_STD_THREAD_LOCAL=0`\n- apple clang (pthread implementation): `clang++ -std=c++11 test.cpp`\n- vs\u003e=2015 `c++11` thread_local: `cl /EHsc test.cpp`\n- vs\u003e=2015 FLS implementation: `cl /EHsc test.cpp -DUSE_STD_THREAD_LOCAL=0`\n- vs2013 (FLS implementation): `cl /EHsc test.cpp`\n- mingw `c++11` thread_local: `g++ -std=c++11 test.cpp`\n- mingw FLS implementation: `g++ -std=c++11 test.cpp -D_WIN32_WINNT=0x0600 -DUSE_STD_THREAD_LOCAL=0`\n- mingw pthread implementation: `g++ -std=c++11 test.cpp -DUSE_STD_THREAD_LOCAL=0`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwang-bin%2Fthreadlocal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwang-bin%2Fthreadlocal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwang-bin%2Fthreadlocal/lists"}