8000 GitHub - sumofat/jobs: Simple job scheduler for Odin
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

sumofat/jobs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jobs

A simple job system for Odin.

Overview

The design is inspired by fiber-based job systems, most notably the one used at Naughty Dog. (see Parallelizing the Naughty Dog Engine).

BUT This scheduler doesn't use fibers! The queued jobs are just executed directly on the waiting thread. From an API perspective, this is basically the same as fibers. It might require more stack space in your worker threads, but there is no need to allocate stacks for fibers.

Also there is no chance of ending up on another thread after using wait, so you can use TLS and OS-provided synchronization primitives like Mutexes and Semaphores.

Features:

  • dispatching and waiting for jobs to finish
  • nested jobs
  • utilities for batch processing of slices/arrays
  • full control over the thread processing loop

Notes:

  • the jobs are queued on a linked list (FILO queue)
  • individual jobs are allocated with context.temp_allocator (or manually)
  • all jobs have to finish the frame you start them (and before calling free_all(context.temp_allocator)!

A simple hello world program

main :: proc() {
    jobs.initialize()

    g: jobs.Group
    jobs.dispatch(.Medium, jobs.make_job(&g, hello_job))
    jobs.wait(&g)

    jobs.shutdown()
}

hello_job :: proc(_: rawptr) {
    fmt.println("Hello from thread", jobs.current_thread_index())
}

Examples

See the examples directory for all examples.

All examples:

  • hello - a very basic introduction to jobs
  • simple - simple overview with most of the features
  • boids - boids simulation with Raylib

boids boids

TODO

  • improve the examples (boids are especially wonky)
  • use atomic linked list instead of spinlocks

Contributing

All contributions are welcome!

About

Simple job scheduler for Odin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Odin 100.0%
0