Skip to content
This repository has been archived by the owner on Mar 12, 2022. It is now read-only.

lucy::wait() needs a worker #2

Open
LordSk opened this issue Jun 20, 2019 · 2 comments
Open

lucy::wait() needs a worker #2

LordSk opened this issue Jun 20, 2019 · 2 comments

Comments

@LordSk
Copy link

LordSk commented Jun 20, 2019

First, thank you for sharing your work. I just so happened to want a job system for my project and thought I would start by testing yours.

So in my project, I have 2 threads dedicated to certain tasks and the remaining would be workers. In one of the dedicated thread, I create a few jobs to be run:

lucy::SignalHandle finished = lucy::INVALID_HANDLE;
for (int i = 0; i < 10; ++i) {
    lucy::run(nullptr, jobB, &finished);
}
lucy::wait(finished);

lucy::wait() calls getWorker() which is null since we did not create any worker on this thread.
I have attached a simple example (based on your main.cpp example code) if you want to reproduce the bug.

main.zip

@nem0
Copy link
Owner

nem0 commented Jun 20, 2019

Hi LordSk,
there are two options. One is to deal with it like I do in the demo https://github.com/nem0/lucy_job_system/blob/master/src/main.cpp#L46. Another is the way like I do it Lumix Engine https://github.com/nem0/LumixEngine/blob/ffr/src/engine/job_system.cpp#L565-L579. Both options will block the calling thread, which might be not what you want.

Ideally, such thread should help with jobs while waiting. This is however not possible in fiber-based job system since the thread would have to be converted to a fiber thread, which I can not do since it's user's thread. In Lumix Engine, I have a backup worker threds, which I enable in such cases https://github.com/nem0/LumixEngine/blob/ffr/src/renderer/renderer.cpp#L922

Let me know which option is the best for you.

@LordSk
Copy link
Author

LordSk commented Jun 22, 2019

Hello nem0.

I expected the behaviour of wait to be the one you linked (https://github.com/nem0/LumixEngine/blob/ffr/src/engine/job_system.cpp#L565-L579), a blocking wait. I decided to make my own job system for the time being as lucy does not seem suited for what I intended to make. I want to run jobs sometimes (like loading data in the background for example), and lucy seems very much built towards running a lot of jobs, all the time.

For the time being, I kindly suggest updating the mini docs to make the wait() function's behaviour a bit clearer.

Thank you for the detailed answer nem0, I will definitely come back to lucy when I get around to making an everything is a job program.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants