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

way to control the scheduler #28

Open
alkis opened this issue Jan 18, 2018 · 5 comments
Open

way to control the scheduler #28

alkis opened this issue Jan 18, 2018 · 5 comments
Labels

Comments

@alkis
Copy link
Contributor

alkis commented Jan 18, 2018

This can allow some usecases:

  • for a given coroutine/scope limit parallelism to 1
  • pin a coroutine/scope to a specific thread (UI thread for example)

Perhaps this is already possible?

@Xudong-Huang
Copy link
Owner

for a given coroutine/scope limit parallelism to 1

this is possible with the following configuration

may::config().set_workers(1).set_io_workers(0);

pin a coroutine/scope to a specific thread (UI thread for example)

no, currently may doesn't support coroutine thread affinity.

@alkis
Copy link
Contributor Author

alkis commented Jan 19, 2018

Wouldn't:

may::config().set_workers(1).set_io_workers(0);

set parallelism to 1 across all coroutines?

What I want to do is to have a function:

fn doStuff() {}

and all coroutines that run through it have constrained parallelism.

@Xudong-Huang
Copy link
Owner

can Mutex/Semphore fullfill the requirement?

@alkis
Copy link
Contributor Author

alkis commented Jan 19, 2018

It will do the work but it seems to me that it does more work than necessary.

The scheduler already does the synchronization (fences/etc) necessary when a coroutine switches from one thread to another. If for example it happens that most of the time doStuff() is running with 1 parallelism, having a scheduler constraint will amount to an atomic increment and decrement. Assuming the doStuff() is not contended, this will be super fast.

Mutex seems much heavier than that. Perhaps I am missing something?

@Xudong-Huang
Copy link
Owner

The sync primitives used in coroutine context doesn't involve system calls, and they are just running in user space which is fast.

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

No branches or pull requests

2 participants