{"id":15047766,"url":"https://github.com/massimo-marino/deferred-thread-scheduler","last_synced_at":"2026-04-01T18:24:38.584Z","repository":{"id":162666660,"uuid":"110897496","full_name":"massimo-marino/deferred-thread-scheduler","owner":"massimo-marino","description":"A C++17 implementation of a deferred thread scheduler","archived":false,"fork":false,"pushed_at":"2019-12-05T11:13:03.000Z","size":49,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-28T00:37:09.724Z","etag":null,"topics":["concurrency","concurrency-library","cpp","cpp17","cpp1z","deferred-tasks","scheduler","thread","thread-scheduler"],"latest_commit_sha":null,"homepage":null,"language":"C++","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/massimo-marino.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":"2017-11-15T23:12:06.000Z","updated_at":"2021-07-07T06:58:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"e2a7d9de-6fc5-4f3d-b9ea-914ac7cc5833","html_url":"https://github.com/massimo-marino/deferred-thread-scheduler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/massimo-marino/deferred-thread-scheduler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/massimo-marino%2Fdeferred-thread-scheduler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/massimo-marino%2Fdeferred-thread-scheduler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/massimo-marino%2Fdeferred-thread-scheduler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/massimo-marino%2Fdeferred-thread-scheduler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/massimo-marino","download_url":"https://codeload.github.com/massimo-marino/deferred-thread-scheduler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/massimo-marino%2Fdeferred-thread-scheduler/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31290838,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T13:12:26.723Z","status":"ssl_error","status_checked_at":"2026-04-01T13:12:25.102Z","response_time":53,"last_error":"SSL_read: 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":["concurrency","concurrency-library","cpp","cpp17","cpp1z","deferred-tasks","scheduler","thread","thread-scheduler"],"created_at":"2024-09-24T21:04:19.945Z","updated_at":"2026-04-01T18:24:38.558Z","avatar_url":"https://github.com/massimo-marino.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# deferred-thread-scheduler\nA C++17 implementation of a deferred thread scheduler\n\n## Requirements\n\n`cmake` is used to compile the sources.\n\nThe default compiler used is `clang++-9.0`.\n\nThe cmake files compile with `-std=c++17`.\n\nThe unit tests are implemented in `googletest`: be sure you have installed `googletest` to compile.\n\n\n## Install and Run Unit Tests\n\n```bash\n$ git clone git@github.com:massimo-marino/deferred-thread-scheduler.git\n$ cd deferred-thread-scheduler/\n$ mkdir build\n$ cd build\n$ cmake ..\n$ make\n$ cd src/unitTests\n$ ./unitTests\n```\nThe unit tests provide examples of usage.\n\n\n## The Deferred Thread Scheduler\n\nA template class named `deferredThreadScheduler` that manages the execution of deferred tasks.\n\nThis class allows the creation of instances that:\n\n- take: a string that identifies a thread; a callable object that identifies the function to be run as a thread; a deferred time in seconds when the thread must be started counted from the time the method `runIn()` is called;\n\n- provide a method for cancelling a scheduled thread; the cancel request is to be ignored if the thread has already started.\n\n\n## Example\n\nHow to install and run the example:\n\n```bash\n$ git clone git@github.com:massimo-marino/deferred-thread-scheduler.git\n$ cd deferred-thread-scheduler/\n$ mkdir build\n$ cd build\n$ cmake ..\n$ make\n$ cd src/example\n$ ./example\n\n[main] Deferred Thread Scheduler Example STARTED\n[main] Registered: OK\n[main] Scheduled: OK\n[main] Run: OK\n[main] Thread result: 'Hello World!!!'\n[main] Deferred Thread Scheduler Example ENDED\n```\n\nThe example source code commented is here below to show how to use the class.\n\n\n```C++\n/* \n * File:   example.cpp\n * Author: massimo\n * \n * Created on November 17, 2017, 11:57 AM\n */\n\n#include \"../deferredThreadScheduler.h\"\n////////////////////////////////////////////////////////////////////////////////\nauto main() -\u003e int\n{\n  using namespace std::chrono_literals;\n  using namespace deferredThreadScheduler;\n\n  std::cout \u003c\u003c \"\\n[\" \u003c\u003c __func__ \u003c\u003c \"] \"\n            \u003c\u003c \"Deferred Thread Scheduler Example STARTED\\n\";\n\n  // the result type of the thread function\n  using threadResultType = std::string;\n  // the thread function type/signature\n  using threadFun = std::function\u003cthreadResultType(const std::string\u0026, const std::string\u0026)\u003e;\n\n  // the arguments passed to the thread function\n  std::string s1 {\"Hello \"};\n  std::string s2 {\"World!!!\"};\n\n  // the thread function\n  threadFun concatStrings = [](const auto\u0026 str1, const auto\u0026 str2)\n                            {\n                              return str1 + str2;\n                            };\n\n  // create an object for the deferred thread scheduler and register the thread function\n  deferredThreadScheduler\u003cthreadResultType, threadFun\u003e dts {\"concatStrings\", concatStrings, s1, s2};\n\n  if ( dts.isRegistered() )\n  {\n    std::cout \u003c\u003c \"[\" \u003c\u003c __func__ \u003c\u003c \"] \"\n              \u003c\u003c \"Registered: OK\\n\";\n  }\n  else\n  {\n    std::cout \u003c\u003c \"[\" \u003c\u003c __func__ \u003c\u003c \"] \"\n              \u003c\u003c \"Registered: NOT OK\\n\";\n  }\n\n  // the deferred time in seconds\n  auto deferredTime {4s};\n  // schedule the thread to run in deferredTime seconds from now\n  dts.runIn(deferredTime);\n\n  if ( dts.isScheduled() )\n  {\n    std::cout \u003c\u003c \"[\" \u003c\u003c __func__ \u003c\u003c \"] \"\n              \u003c\u003c \"Scheduled: OK\\n\";\n  }\n  else\n  {\n    std::cout \u003c\u003c \"[\" \u003c\u003c __func__ \u003c\u003c \"] \"\n              \u003c\u003c \"Scheduled: NOT OK\\n\";\n  }\n\n  // wait here the end of the thread\n  auto [threadState, threadResult] = dts.wait_for(3950ms);\n  // dont loop forever, just some more time after the time-out\n  for(auto i {1}; i \u003c= 200 \u0026\u0026 false == dts.isRun(threadState); ++i)\n  {\n    std::tie(threadState, threadResult) = dts.wait_for(1ms);\n  }\n\n  if ( dts.isRun(threadState) )\n  {\n    std::cout \u003c\u003c \"[\" \u003c\u003c __func__ \u003c\u003c \"] \"\n              \u003c\u003c \"Run: OK\\n\";\n  }\n  else\n  {\n    std::cout \u003c\u003c \"[\" \u003c\u003c __func__ \u003c\u003c \"] \"\n              \u003c\u003c \"Run: NOT OK\\n\";\n  }\n\n  std::cout \u003c\u003c \"[\" \u003c\u003c __func__ \u003c\u003c \"] \"\n            \u003c\u003c \"Thread result: '\"\n            \u003c\u003c threadResult\n            \u003c\u003c \"'\\n\";\n\n  std::cout \u003c\u003c \"[\" \u003c\u003c __func__ \u003c\u003c \"] \"\n            \u003c\u003c \"Deferred Thread Scheduler Example ENDED\\n\"\n            \u003c\u003c std::endl;\n\n  return 0;\n}  // main\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmassimo-marino%2Fdeferred-thread-scheduler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmassimo-marino%2Fdeferred-thread-scheduler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmassimo-marino%2Fdeferred-thread-scheduler/lists"}