{"id":26491992,"url":"https://github.com/zig-gamedev/zjobs","last_synced_at":"2025-07-27T17:09:29.010Z","repository":{"id":270771452,"uuid":"882851728","full_name":"zig-gamedev/zjobs","owner":"zig-gamedev","description":"Generic job queue implementation for Zig.","archived":false,"fork":false,"pushed_at":"2025-07-20T21:30:56.000Z","size":15,"stargazers_count":10,"open_issues_count":2,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-07-20T23:29:09.864Z","etag":null,"topics":["gamedev","job-queue","multithreading","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","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/zig-gamedev.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":"2024-11-03T23:03:29.000Z","updated_at":"2025-07-20T21:30:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"2980e6b5-d4be-4037-ba5a-45ebeac66b0a","html_url":"https://github.com/zig-gamedev/zjobs","commit_stats":null,"previous_names":["zig-gamedev/zjobs"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zig-gamedev/zjobs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzjobs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzjobs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzjobs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzjobs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zig-gamedev","download_url":"https://codeload.github.com/zig-gamedev/zjobs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzjobs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267392562,"owners_count":24079919,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"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":["gamedev","job-queue","multithreading","zig"],"created_at":"2025-03-20T08:51:36.628Z","updated_at":"2025-07-27T17:09:28.950Z","avatar_url":"https://github.com/zig-gamedev.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [zjobs](https://github.com/zig-gamedev/zig-gamedev/tree/main/libs/zjobs)\n\nGeneric job queue implementation for Zig.\n\nIn order to take full advantage of modern multicore CPUs, it is necessary to\nrun much of your application logic on separate threads.  This `JobQueue`\nprovides a simple API to schedule \"jobs\" to run on a pool of threads, typically\nas many threads as your CPU supports, less 1 (the main thread).\n\nEach \"job\" is a user-defined struct that declares a `exec` function that will\nbe executed on a background thread by the `JobQueue`.\n\n## Getting started\n\nExample `build.zig`:\n\n```zig\npub fn build(b: *std.Build) void {\n    const exe = b.addExecutable(.{ ... });\n\n    const zjobs = b.dependency(\"zjobs\", .{});\n    exe.root_module.addImport(\"zjobs\", zjobs.module(\"root\"));\n}\n```\n\n## Example Usage\n\nThe following example is also a `test` case in `zjobs.zig`:\n\n```zig\nconst Jobs = JobQueue(.{}); // a default-configured `JobQueue` type\n\nvar jobs = Jobs.init(); // initialize an instance of `Jobs`\ndefer jobs.deinit(); // ensure that `jobs` is cleaned up when we're done\n\n// First we will define a job that will print \"hello \" when it runs.\n// The job must declare a `exec` function, which defines the code that\n// will be executed on a background thread by the `JobQueue`.\n// Our `HelloJob` doesn't contain any member variables, but it could.\n// We will see an example of a job with some member variables below.\nconst HelloJob = struct {\n    pub fn exec(_: *@This()) void {\n        print(\"hello \", .{});\n    }\n};\n\n// Now we will schedule an instance of `HelloJob` to run on a separate\n// thread.\n// The `schedule()` function returns a `JobId`, which is how we can refer\n// to this job to determine when it is done.\n// The first argument to `schedule()` is the `prereq`, which\n// specifies a job that must be completed before this job can run.\n// Here, we specify the `prereq` of `JobId.none`, which means that\n// this job does not need to wait for any other jobs to complete.\n// The second argument to `schedule()` is the `job`, which is a user-\n// defined struct that declares a `exec` function that will be executed\n// on a background thread.\n// Here we are providing an instance of our `HelloJob` defined above.\nconst hello_job_id: JobId = try jobs.schedule(\n    JobId.none, // does not wait for any other job\n    HelloJob{}, // runs `HelloJob.exec()` on another thread\n);\n\n// Scheduled jobs will not execute until `start()` is called.\n// The `start()` function spawns the threads that will run the jobs.\n// Note that we can schedule jobs before and after calling `start()`.\njobs.start();\n\n// Now we will schedule a second job that will print \"world!\" when it runs.\n// We want this job to run after the `HelloJob` completes, so we provide\n// `hello_job_id` as the `prereq` when scheduling this job.\n// This ensures that the string \"hello \" will be printed before we print\n// the string \"world!\\n\"\n// This time, we will use an anonymous struct to declare the job directly\n// within the call to `schedule()`.\n// Note the trailing empty braces, `{}`, which initialize an instance of\n// this anonymous struct.\nconst world_job_id: JobId = try jobs.schedule(\n    hello_job_id, // waits for `hello_job_id` to be completed\n    struct {\n        fn exec(_: *@This()) void {\n            print(\"world!\\n\", .{});\n        }\n    }{}, // trailing `{}` initializes an instance of this anonymous struct\n);\n\n// When we want to shut down all of the background threads, we can call\n// the `stop()` function.\n// Here we will schedule a job to call `stop()` after our \"world!\" job\n// completes.\n// This ensures that the string \"hello world!\\n\" will be printed before\n// we stop running our jobs.\n// Note that our anonymous \"stop job\" captures a pointer to `jobs` so that\n// it can call `stop()`.\n_ = try jobs.schedule(\n    world_job_id, // waits for `world_job_id` to be completed\n    struct {\n        jobs: *Jobs, // stores a pointer to `jobs`\n        fn exec(self: *@This()) void {\n            self.jobs.stop();\n        }\n    }{ // trailing `{}` initializes an instance of this anonymous struct\n        .jobs = \u0026jobs, // and initializes a pointer to `jobs` here\n    },\n);\n\n// Now that we're done, we can call `join()` to wait for all of the\n// background threads to finish processing scheduled jobs.\njobs.join();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzig-gamedev%2Fzjobs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzig-gamedev%2Fzjobs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzig-gamedev%2Fzjobs/lists"}