All Projects → nem0 → lucy_job_system

nem0 / lucy_job_system

Licence: MIT license
Fiber-based job system with extremely simple API

Programming Languages

C++
36643 projects - #6 most used programming language
lua
6591 projects
Batchfile
5799 projects

Projects that are alternatives of or similar to lucy job system

Fiber Job System
Multi-Threaded Job System using Fibers
Stars: ✭ 121 (+55.13%)
Mutual labels:  fibers, multithreading
Taskscheduler
Cross-platform, fiber-based, multi-threaded task scheduler designed for video games.
Stars: ✭ 402 (+415.38%)
Mutual labels:  fibers, multithreading
Fibry
The first Java Actor System supporting fibers from Project Loom
Stars: ✭ 146 (+87.18%)
Mutual labels:  fibers, multithreading
Fibertaskinglib
A library for enabling task-based multi-threading. It allows execution of task graphs with arbitrary dependencies.
Stars: ✭ 679 (+770.51%)
Mutual labels:  fibers, multithreading
AIO
Coroutine-based multithreading library for Delphi
Stars: ✭ 99 (+26.92%)
Mutual labels:  fibers, multithreading
wasm-bindgen-rayon
An adapter for enabling Rayon-based concurrency on the Web with WebAssembly.
Stars: ✭ 257 (+229.49%)
Mutual labels:  multithreading
theater
Actor framework for Dart. This package makes it easier to work with isolates, create clusters of isolates.
Stars: ✭ 29 (-62.82%)
Mutual labels:  multithreading
TaskManager
A C++14 Task Manager / Scheduler
Stars: ✭ 81 (+3.85%)
Mutual labels:  multithreading
HTTPStaticServer
Bare-bones static HTTP server written in a single C file
Stars: ✭ 24 (-69.23%)
Mutual labels:  multithreading
b-rabbit
A thread safe library that aims to provide a simple API for interfacing with RabbitMQ. Built on top of rabbitpy, the library make it very easy to use the RabbitMQ message broker with just few lines of code. It implements all messaging pattern used by message brokers
Stars: ✭ 15 (-80.77%)
Mutual labels:  multithreading
hostbase
A Ruby GUI based on advanced rogue AP attack using the WPS
Stars: ✭ 43 (-44.87%)
Mutual labels:  multithreading
ObviousAwait
🧵 Expressive aliases to ConfigureAwait(true) and ConfigureAwait(false)
Stars: ✭ 55 (-29.49%)
Mutual labels:  multithreading
workerpoolxt
Concurrency limiting goroutine pool without upper limit on queue length. Extends github.com/gammazero/workerpool
Stars: ✭ 15 (-80.77%)
Mutual labels:  multithreading
bullshit-job-titles
the shittiest job titles you'll ever see
Stars: ✭ 105 (+34.62%)
Mutual labels:  job
disruptor-billing-example
Example LMAX Disruptor spring-boot project that uses disruptor-spring-manager framework
Stars: ✭ 56 (-28.21%)
Mutual labels:  multithreading
Planeverb
Project Planeverb is a CPU based real-time wave-based acoustics engine for games. It comes with an integration with the Unity Engine.
Stars: ✭ 22 (-71.79%)
Mutual labels:  multithreading
triple-buffer
Implementation of triple buffering in Rust
Stars: ✭ 66 (-15.38%)
Mutual labels:  multithreading
content-downloader
Python package to download files on any topic in bulk.
Stars: ✭ 102 (+30.77%)
Mutual labels:  multithreading
asynchronous
A D port of Python's asyncio library
Stars: ✭ 35 (-55.13%)
Mutual labels:  fibers
muco
Multithreaded Coroutines library
Stars: ✭ 20 (-74.36%)
Mutual labels:  fibers

Lucy Job System

This is outdated compared to Lumix Engine. Use that instead.

Fiber-based job system with extremely simple API.

It's a standalone version of job system used in Lumix Engine. Only Windows is supported now, although the Lumix Engine version has Linux support, I have to copy it here yet.

Demo

Create a solution with create_solution_vs2017.bat. The solution is in build/tmp/. Open the solution, compile and run.

#include "lucy.h"
#include <condition_variable>
#include <cstdio>
#include <mutex>


std::mutex g_mutex;
std::condition_variable g_finished;
std::mutex g_finished_mutex;


void print(const char* msg)
{
	std::lock_guard lock(g_mutex);
	printf(msg);
	printf("\n");
}


void jobB(void*)
{
	print("B begin");
	print("B end");
}


void jobA(void*)
{
	print("A begin");
	lucy::SignalHandle finished = lucy::INVALID_HANDLE;
	for(int i = 0; i < 10; ++i) {
		lucy::run(nullptr, jobB, &finished);
	}
	lucy::wait(finished);
	print("A end");
	g_finished.notify_all();
}


int main(int argc, char* argv[])
{
	lucy::init();
	lucy::run(nullptr, jobA, nullptr);
	std::unique_lock<std::mutex> lck(g_finished_mutex);
	g_finished.wait(lck);
	lucy::shutdown();
}

Integration

Just put lucy.h and lucy.cpp in your project and you are good to go.

Docs

See src/main.cpp for an example.

Initialization / shutdown

lucy::init() must be called before any other function from lucy namespace lucy::shutdown() call this when you don't want to run any more jobs. Make sure all jobs are finished before calling this, since it does not wait for jobs to finish.

Jobs

Job is a function pointer with associated void data pointer. When job is executed, the function is called and the data pointer is passed as a parameter to this function.

lucy::run push a job to global queue

int value = 42;
lucy::run(&value, [](void* data){
	printf("%d", *(int*)data);
}, nullptr);

This prints 42. Eventually, after the job is finished, a signal can be triggered, see signals for more information.

Signals

lucy::SignalHandle signal = lucy::INVALID_HANDLE;
lucy::wait(signal); // does not wait, since signal is invalid
lucy::incSignal(&signal);
lucy::wait(signal); // wait until someone calls lucy::decSignal, execute other jobs in the meantime
lucy::SignalHandle signal = lucy::INVALID_HANDLE;
for (int i = 0; i < N; ++i) {
	lucy::incSignal(&signal);
}
lucy::wait(signal); // wait until lucy::decSignal is called N-times

If a signal is passed to lucy::run (3rd parameter), then the signal is automatically incremented. It is decremented once all the job is finished.

lucy::SignalHandle finished = lucy::INVALID_HANDLE;
for(int i = 0; i < 10; ++i) {
	lucy::run(nullptr, job_fn, &finished);
}
lucy::wait(finished); // wait for all 10 jobs to finish

There's no need to destroy signals, it's "garbage collected".

Signals can be used as preconditions to run a job. It means a job starts only after the signal is signalled:

lucy::SignalHandle precondition = getPrecondition();
lucy::runEx(nullptr, job_fn, nullptr, precondition, lucy::ANY_WORKER);

is functionally equivalent to:

void job_fn(void*) { 
	lucy::wait(precondition);
	dowork();
}
lucy::run(nullptr, job_fn, nullptr);

However, the lucy::runEx version has better performance.

Finally, a job can be pinned to specific worker thread. This is useful for calling APIs which must be called from the same thread, e.g. OpenGL functions or WinAPI UI functions.

lucy::runEx(nullptr, job_fn, nullptr, lucy::INVALID_HANDLE, 3); // run on worker thread 3
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].