Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread pinning #284

Open
randy408 opened this issue Dec 16, 2020 · 1 comment
Open

Thread pinning #284

randy408 opened this issue Dec 16, 2020 · 1 comment
Labels
enhancement New feature or request will take a while This will take a while

Comments

@randy408
Copy link
Contributor

randy408 commented Dec 16, 2020

Describe the problem you are trying to solve.
Pinning systems to threads is important to keep specific library calls on the main thread, prevent splitting of a module's systems across threads and to allow thread-safe systems to run on any thread at the same time.

Describe the solution you'd like

* Updated *

  • Introduce the concept of a main flecs thread which is the ecs_progress() thread / thread index 0 as far as flecs is concerned.

  • For backward compatibility existing systems should run on the main thread unless specified otherwise

  • With the exception of the main thread, thread pinning should be always to be to a pseudo-thread, the flecs thread index could change at any time as long as the pinned systems don't run on different threads, this only has to be a specification at first.

  • For systems that are threadsafe there should be an easy way to mark them as such

// Always run on thread idx 0 by default
ECS_SYSTEM("Move", "Position, Velocity");

//Mark system as thread-safe, alternative names: MultiThread, AllThreads, AnyThread
ECS_SYSTEM("X", "SYSTEM:ThreadSafe Lorem, Ipsum");

//Creates an entity
ECS_THREAD(MotionThread);

//"Thread" is a builtin trait, makes it more obvious `MotionThread` is a thread
//System is not split across threads, but the thread index may change
ECS_SYSTEM("Move", "SYSTEM:Thread FOR MotionThread, Position, Velocity");

//Also not split across threads and on the same thread as Move
ECS_SYSTEM("X", "SYSTEM:Thread FOR MotionThread Lorem, Ipsum");

//Alternative syntax
ECS_SYSTEM("Move", "THREAD:MotionThread Position, Velocity");

Why something like THREAD:0-N would be a bad idea:
Modules from different sources could hog the same thread and assumes flecs will spawn N threads, named threads are also better for debugging.

@randy408 randy408 added the enhancement New feature or request label Dec 16, 2020
@alex-rass-88
Copy link

Have some question about threading. Can i create custom pipeline with some stages marked as single threaded? I need 2 stages what runs on main thread and 5 stages what multi threaded.

@SanderMertens SanderMertens added the will take a while This will take a while label Mar 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request will take a while This will take a while
Projects
None yet
Development

No branches or pull requests

3 participants