[rust-dev] How to kill a child task from parent?

Alex Crichton alex at crichton.co
Wed Jun 4 11:17:14 PDT 2014


Rust tasks do not support being killed at arbitrary points. You'll
have to arrange ahead of time for a "please die" message to be sent a
long a channel, or a similar scheme for transmitting this information.

On Wed, Jun 4, 2014 at 9:33 AM, Aravinda VK <hallimanearavind at gmail.com> wrote:
> Hi,
>
> I am trying different alternative to kill a task from parent, But I didn't
> get any ways to kill a task from its parent.
>
> In the following approach I started worker2 inside worker1 and worker1 from
> main. After 1000 miliseconds worker1 dies, but worker2 still continues.
>
>     use std::io::timer::sleep;
>
>     fn worker1(){
>         spawn(proc() {
>             worker2();
>         });
>         println!("worker 1");
>         sleep(1000);
>         fail!("I am done");
>     }
>
>     fn worker2(){
>         loop{
>             println!("worker 2");
>         }
>     }
>
>     fn main(){
>         spawn(proc() {
>             worker1();
>         });
>     }
> Any suggestions?
>
> --
> Regards
> Aravinda | ಅರವಿಂದ
> http://aravindavk.in
>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>


More information about the Rust-dev mailing list