This is very cool.
On 2/8/12 5:21 PM, Brian Anderson wrote:
Hey.
One of the several painful things about creating bindings for native libraries
is that calling blocking functions prevents other tasks from making progress.
This makes using things like sockets or libuv problematic. No more - a solution
is here!
The runtime now allows for schedulers to be created and added dynamically, and
by creating your own scheduler you can block for as long as you like without
interfering with tasks on other schedulers.
We currently have a single function that can be used to take advantage of this:
core::task::spawn_sched. It spawns a new task into a new scheduler and takes an
argument for the number of OS threads the scheduler should use.
spawn_sched(1) {||
// do some blocky sockets business
}
// go on my merry way
The scheduler will die when all tasks running on it die. By default (when not
using spawn_sched), tasks inherit their schedulers, so if your blocky task
wants to spawn other tasks that shouldn't be interfered with it will need to do
so through an intermediary on a different scheduler (which is easy enough to do
with unique closures).
This interface will continue to change.
Regards,
Brian
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev