Skip to content

document task scheduler #3441

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

Closed
jesse99 opened this issue Sep 10, 2012 · 9 comments
Closed

document task scheduler #3441

jesse99 opened this issue Sep 10, 2012 · 9 comments

Comments

@jesse99
Copy link
Contributor

jesse99 commented Sep 10, 2012

task.rs is a bit overwhelming and very difficult to understand how to use correctly. I think it would be helpful to document a bit better the theory of operation, the default scheduling mode, and probably even some examples for common tasks (even if its just pointers to suitable unit tests).

For example just how are users supposed to deal with foreign code that blocks? In the simple case I guess SingleThreaded would do the trick. But what about more complex cases? What if I need to call a foreign blocking function, wait for it to respond, and then kick off a bunch of concurrent tasks? Is there a way to spawn that task with SingleThreaded without changing the scheduling of its child tasks?

@brson
Copy link
Contributor

brson commented Sep 10, 2012

As far as your last question, there's no code to support this pattern yet, but the basic way to deal with this is to have the blocking task send spawn requests back to another task on the original scheduler.

@jesse99
Copy link
Contributor Author

jesse99 commented Sep 25, 2012

Some usage examples would certainly be handy, but this particular case is not hard. As best I can tell the blocking thread should be started with either SingleThreaded (if it spends most if its time blocked) or ManualThreads(1) (if it does substantial amounts of work between blocking).

When the blocking thread needs to spawn off new tasks it simply uses spawn_sched(ThreadPerCore) which will cause those tasks to share the default threads.

@brson
Copy link
Contributor

brson commented Sep 25, 2012

SingleThreaded and ManualThreads(1) are identical. Calling spawn_sched(ThreadPerCore) will not cause the new tasks to go back to the default scheduler, it will create an entirely new scheduler for each call.

@brson
Copy link
Contributor

brson commented Sep 25, 2012

I'm still hoping to get a full task tutorial in for 0.4 and improve the rustdocs.

@jesse99
Copy link
Contributor Author

jesse99 commented Sep 25, 2012

I think I understand how it's supposed to work now. Bit painful to spin up a task just to create sub-tasks elsewhere within the right scheduler. Also quite error prone and will require that I touch lots of code.

I think the answer in my case is to just use ManualThreads(small n) when I kick off a task to handle a new client connection. When that task needs to spawn sub-tasks it can just use task::spawn. More threads than I'd like but it's simple and should work reasonably well.

@sanxiyn
Copy link
Member

sanxiyn commented Mar 26, 2013

Task tutorial now exists.

@catamorphism
Copy link
Contributor

Nominating for milestone 4, well-covered (if there is still work to do on this).

@graydon
Copy link
Contributor

graydon commented Jun 20, 2013

accepted for well-covered milestone

@graydon
Copy link
Contributor

graydon commented Aug 7, 2013

I think this is suitably covered by the task tutorial; if not, it needs to be more specific about what docs are required (beyond "more always"; that's not specific enough to be a bug since it'll never close).

Meanwhile, closing this.

@graydon graydon closed this as completed Aug 7, 2013
bors pushed a commit to rust-lang-ci/rust that referenced this issue May 15, 2021
RalfJung pushed a commit to RalfJung/rust that referenced this issue Apr 6, 2024
shims/unix: split general FD management from FS access

`fd.rs` was a mix of general file descriptor infrastructure and file system access. Split those things up properly.

Also add a `socket.rs` file where support for sockets can go eventually. For now it just contains the socketpair stub.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants