{"id":26145675,"url":"https://github.com/carlowood/threadsafe","last_synced_at":"2026-03-07T00:32:20.205Z","repository":{"id":28069832,"uuid":"31566912","full_name":"CarloWood/threadsafe","owner":"CarloWood","description":"Threading utilities: object oriented (read/write) locking and more.","archived":false,"fork":false,"pushed_at":"2025-12-13T22:34:54.000Z","size":213,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-15T18:28:06.243Z","etag":null,"topics":["barrier-gate","c-plus-plus","cpp17","futex","gate","linux","locking","locking-policies","locks","mutex","readwrite","semaphore","thread-safe","threading","threadsafe"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CarloWood.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,"zenodo":null}},"created_at":"2015-03-02T22:30:44.000Z","updated_at":"2025-12-13T22:34:58.000Z","dependencies_parsed_at":"2025-04-14T03:09:37.182Z","dependency_job_id":"478f25b7-e8f1-4f0a-a91e-48e711d9fe60","html_url":"https://github.com/CarloWood/threadsafe","commit_stats":null,"previous_names":["carlowood/ai-threadsafe"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CarloWood/threadsafe","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CarloWood%2Fthreadsafe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CarloWood%2Fthreadsafe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CarloWood%2Fthreadsafe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CarloWood%2Fthreadsafe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CarloWood","download_url":"https://codeload.github.com/CarloWood/threadsafe/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CarloWood%2Fthreadsafe/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30204154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T19:07:06.838Z","status":"ssl_error","status_checked_at":"2026-03-06T18:57:34.882Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["barrier-gate","c-plus-plus","cpp17","futex","gate","linux","locking","locking-policies","locks","mutex","readwrite","semaphore","thread-safe","threading","threadsafe"],"created_at":"2025-03-11T04:54:39.087Z","updated_at":"2026-03-07T00:32:20.157Z","avatar_url":"https://github.com/CarloWood.png","language":"C++","readme":"# threadsafe submodule\n\nThis repository is a [git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules)\nproviding C++ utilities for larger projects, including:\n\n* \u003ctt\u003ethreadsafe::Unlocked\u0026lt;T, policy::P\u0026gt;\u003c/tt\u003e : template class to construct a T / mutex pair with locking policy P.\n* \u003ctt\u003eReadWrite\u003c/tt\u003e, \u003ctt\u003ePrimitive\u003c/tt\u003e, \u003ctt\u003eOneThread\u003c/tt\u003e : Locking policies.\n* \u003ctt\u003eAccessConst\u003c/tt\u003e and \u003ctt\u003eAccess\u003c/tt\u003e : Obtain read/write access to Primitive or OneThread locked objects.\n* \u003ctt\u003eConstReadAccess\u003c/tt\u003e, \u003ctt\u003eReadAccess\u003c/tt\u003e and \u003ctt\u003eWriteAccess\u003c/tt\u003e : Obtain access to ReadWrite protected objects.\n* \u003ctt\u003eAIReadWriteMutex\u003c/tt\u003e : A mutex class that provides read/write locking.\n* \u003ctt\u003eUnlockedBase\u003c/tt\u003e : A base class pointer to an Unlocked object that can be used in the same way.\n* Several utilities like \u003ctt\u003eis_single_threaded\u003c/tt\u003e.\n\nThe root project should be using\n[cmake](https://cmake.org/overview/)\n[cwm4](https://github.com/CarloWood/cwm4) and\n[libcwd](https://github.com/CarloWood/libcwd).\n\n## Example\n\nFor example, to create an object of type \u003ctt\u003eFoo\u003c/tt\u003e\nthat has read/write protection, one could do:\n\n```C++\nusing namespace threadsafe;\nusing foo_t = Unlocked\u003cFoo, policy::ReadWrite\u003cAIReadWriteMutex\u003e\u003e;\n\n// Create an object Foo, AIReadWriteMutex pair. Foo will be inaccessible.\nfoo_t foo;\n\n// A function that gets an already read-locked foo passed, created from a const foo_t.\nvoid f(foo_t::crat const\u0026 foo_cr) { foo_cr-\u003econst_member(); }\n\n// A function that gets a non-const foo_t passed and write locks it to get write access.\nvoid g(foo_t\u0026 foo)\n{\n  foo_t::wat foo_w(foo);        // Obtain lock.\n  foo_w-\u003ewrite_access();\n  f(foo_w);                     // Being write locked is OK to pass too.\n}                               // Release lock.\n\n// A function that gets a read-locked foo passed but needs write access.\nvoid h(foo_t::rat\u0026 foo_r)\n{\n  // The next line might throw, see below. Normally it would just\n  // block until all other threads released their read-locks.\n  foo_t::wat foo_w(foo_r);      // Convert read to write lock without releasing the lock.\n  foo_w-\u003ewrite_access();\n}\n\n// A function that takes a read-lock most of the time\n// but needs to call h() at the end.\nvoid v(foo_t\u0026 foo)\n{\n  for(;;) {\n    try {\n      foo_t::rat foo_r(foo);\n      // Stuff here during which we cannot release the read lock.\n      h(foo_r); // Throws if some other thread is also trying to get a read--\u003ewrite lock.\n    } catch(std::exception const\u0026) {\n      foo.rd2wryield();\n      continue;\n    }\n    break;\n  }\n}\n```\n\n## Checking out a project that uses the threadsafe submodule.\n\nTo clone a project example-project that uses threadsafe simply run:\n\n    git clone --recursive \u003cURL-to-project\u003e/example-project.git\n    cd example-project\n    AUTOGEN_CMAKE_ONLY=1 ./autogen.sh\n\nThe ``--recursive`` is optional because ``./autogen.sh`` will fix\nit when you forgot it.\n\nWhen using [GNU autotools](https://en.wikipedia.org/wiki/GNU_Autotools) you should of course\nnot set ``AUTOGEN_CMAKE_ONLY``. Also, you probably want to use ``--enable-mainainer-mode``\nas option to the generated ``configure`` script.\n\nIn order to use ``cmake`` configure as usual, for example to build with 16 cores a debug build:\n\n    mkdir build_debug\n    cmake -S . -B build_debug -DCMAKE_MESSAGE_LOG_LEVEL=DEBUG -DCMAKE_BUILD_TYPE=Debug -DCMAKE_VERBOSE_MAKEFILE=ON -DEnableDebugGlobal:BOOL=OFF\n    cmake --build build_debug --config Debug --parallel 16\n\nOr to make a release build:\n\n    mkdir build_release\n    cmake -S . -B build_release -DCMAKE_BUILD_TYPE=Release\n    cmake --build build_release --config Release --parallel 16\n\n## Adding the threadsafe submodule to a project\n\nTo add this submodule to a project, that project should already\nbe set up to use [utils](https://github.com/CarloWood/ai-utils).\n\nThen simply execute the following in a directory of that project\nwhere you want to have the ``threadsafe`` subdirectory (the\nroot of the project is recommended as that is the only thing\nI've tested so far):\n\n    git submodule add https://github.com/CarloWood/threadsafe.git\n\nThis should clone threadsafe into the subdirectory ``threadsafe``, or\nif you already cloned it there, it should add it.\n\nCheckout [threadsafe-testsuite](https://github.com/CarloWood/threadsafe-testsuite)\nfor an example of a project that uses this submodule.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarlowood%2Fthreadsafe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcarlowood%2Fthreadsafe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarlowood%2Fthreadsafe/lists"}