]> git.lizzy.rs Git - rust.git/blob - src/libstd/rt/task.rs
auto merge of #10787 : nikomatsakis/rust/issue-9629-freeze-andmut, r=pnkfelix
[rust.git] / src / libstd / rt / task.rs
1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Language-level runtime services that should reasonably expected
12 //! to be available 'everywhere'. Local heaps, GC, unwinding,
13 //! local storage, and logging. Even a 'freestanding' Rust would likely want
14 //! to implement this.
15
16 use super::local_heap::LocalHeap;
17
18 use prelude::*;
19
20 use borrow;
21 use cast::transmute;
22 use cleanup;
23 use libc::{c_void, uintptr_t, c_char, size_t};
24 use local_data;
25 use option::{Option, Some, None};
26 use rt::borrowck::BorrowRecord;
27 use rt::borrowck;
28 use rt::context::Context;
29 use rt::context;
30 use rt::env;
31 use io::Writer;
32 use rt::kill::Death;
33 use rt::local::Local;
34 use rt::logging::StdErrLogger;
35 use rt::sched::{Scheduler, SchedHandle};
36 use rt::stack::{StackSegment, StackPool};
37 use send_str::SendStr;
38 use unstable::finally::Finally;
39 use unstable::mutex::Mutex;
40
41 // The Task struct represents all state associated with a rust
42 // task. There are at this point two primary "subtypes" of task,
43 // however instead of using a subtype we just have a "task_type" field
44 // in the struct. This contains a pointer to another struct that holds
45 // the type-specific state.
46
47 pub struct Task {
48     heap: LocalHeap,
49     priv gc: GarbageCollector,
50     storage: LocalStorage,
51     logger: Option<StdErrLogger>,
52     unwinder: Unwinder,
53     death: Death,
54     destroyed: bool,
55     name: Option<SendStr>,
56     coroutine: Option<Coroutine>,
57     sched: Option<~Scheduler>,
58     task_type: TaskType,
59     // Dynamic borrowck debugging info
60     borrow_list: Option<~[BorrowRecord]>,
61     stdout_handle: Option<~Writer>,
62
63     // See the comments in the scheduler about why this is necessary
64     nasty_deschedule_lock: Mutex,
65 }
66
67 pub enum TaskType {
68     GreenTask(Option<SchedHome>),
69     SchedTask
70 }
71
72 /// A coroutine is nothing more than a (register context, stack) pair.
73 pub struct Coroutine {
74     /// The segment of stack on which the task is currently running or
75     /// if the task is blocked, on which the task will resume
76     /// execution.
77     ///
78     /// Servo needs this to be public in order to tell SpiderMonkey
79     /// about the stack bounds.
80     current_stack_segment: StackSegment,
81     /// Always valid if the task is alive and not running.
82     saved_context: Context
83 }
84
85 /// Some tasks have a dedicated home scheduler that they must run on.
86 pub enum SchedHome {
87     AnySched,
88     Sched(SchedHandle)
89 }
90
91 pub struct GarbageCollector;
92 pub struct LocalStorage(Option<local_data::Map>);
93
94 /// Represents the reason for the current unwinding process
95 pub enum UnwindResult {
96     /// The task is ending successfully
97     Success,
98
99     /// The Task is failing with reason `~Any`
100     Failure(~Any),
101 }
102
103 impl UnwindResult {
104     /// Returns `true` if this `UnwindResult` is a failure
105     #[inline]
106     pub fn is_failure(&self) -> bool {
107         match *self {
108             Success => false,
109             Failure(_) => true
110         }
111     }
112
113     /// Returns `true` if this `UnwindResult` is a success
114     #[inline]
115     pub fn is_success(&self) -> bool {
116         match *self {
117             Success => true,
118             Failure(_) => false
119         }
120     }
121 }
122
123 pub struct Unwinder {
124     unwinding: bool,
125     cause: Option<~Any>
126 }
127
128 impl Unwinder {
129     fn to_unwind_result(&mut self) -> UnwindResult {
130         if self.unwinding {
131             Failure(self.cause.take().unwrap())
132         } else {
133             Success
134         }
135     }
136 }
137
138 impl Task {
139
140     // A helper to build a new task using the dynamically found
141     // scheduler and task. Only works in GreenTask context.
142     pub fn build_homed_child(stack_size: Option<uint>,
143                              f: proc(),
144                              home: SchedHome)
145                              -> ~Task {
146         let mut running_task = Local::borrow(None::<Task>);
147         let mut sched = running_task.get().sched.take_unwrap();
148         let new_task = ~running_task.get()
149                                     .new_child_homed(&mut sched.stack_pool,
150                                                      stack_size,
151                                                      home,
152                                                      f);
153         running_task.get().sched = Some(sched);
154         new_task
155     }
156
157     pub fn build_child(stack_size: Option<uint>, f: proc()) -> ~Task {
158         Task::build_homed_child(stack_size, f, AnySched)
159     }
160
161     pub fn build_homed_root(stack_size: Option<uint>,
162                             f: proc(),
163                             home: SchedHome)
164                             -> ~Task {
165         let mut running_task = Local::borrow(None::<Task>);
166         let mut sched = running_task.get().sched.take_unwrap();
167         let new_task = ~Task::new_root_homed(&mut sched.stack_pool,
168                                              stack_size,
169                                              home,
170                                              f);
171         running_task.get().sched = Some(sched);
172         new_task
173     }
174
175     pub fn build_root(stack_size: Option<uint>, f: proc()) -> ~Task {
176         Task::build_homed_root(stack_size, f, AnySched)
177     }
178
179     pub fn new_sched_task() -> Task {
180         Task {
181             heap: LocalHeap::new(),
182             gc: GarbageCollector,
183             storage: LocalStorage(None),
184             logger: None,
185             unwinder: Unwinder { unwinding: false, cause: None },
186             death: Death::new(),
187             destroyed: false,
188             coroutine: Some(Coroutine::empty()),
189             name: None,
190             sched: None,
191             task_type: SchedTask,
192             borrow_list: None,
193             stdout_handle: None,
194             nasty_deschedule_lock: unsafe { Mutex::new() },
195         }
196     }
197
198     pub fn new_root(stack_pool: &mut StackPool,
199                     stack_size: Option<uint>,
200                     start: proc()) -> Task {
201         Task::new_root_homed(stack_pool, stack_size, AnySched, start)
202     }
203
204     pub fn new_child(&mut self,
205                      stack_pool: &mut StackPool,
206                      stack_size: Option<uint>,
207                      start: proc()) -> Task {
208         self.new_child_homed(stack_pool, stack_size, AnySched, start)
209     }
210
211     pub fn new_root_homed(stack_pool: &mut StackPool,
212                           stack_size: Option<uint>,
213                           home: SchedHome,
214                           start: proc()) -> Task {
215         Task {
216             heap: LocalHeap::new(),
217             gc: GarbageCollector,
218             storage: LocalStorage(None),
219             logger: None,
220             unwinder: Unwinder { unwinding: false, cause: None },
221             death: Death::new(),
222             destroyed: false,
223             name: None,
224             coroutine: Some(Coroutine::new(stack_pool, stack_size, start)),
225             sched: None,
226             task_type: GreenTask(Some(home)),
227             borrow_list: None,
228             stdout_handle: None,
229             nasty_deschedule_lock: unsafe { Mutex::new() },
230         }
231     }
232
233     pub fn new_child_homed(&mut self,
234                            stack_pool: &mut StackPool,
235                            stack_size: Option<uint>,
236                            home: SchedHome,
237                            start: proc()) -> Task {
238         Task {
239             heap: LocalHeap::new(),
240             gc: GarbageCollector,
241             storage: LocalStorage(None),
242             logger: None,
243             unwinder: Unwinder { unwinding: false, cause: None },
244             death: Death::new(),
245             destroyed: false,
246             name: None,
247             coroutine: Some(Coroutine::new(stack_pool, stack_size, start)),
248             sched: None,
249             task_type: GreenTask(Some(home)),
250             borrow_list: None,
251             stdout_handle: None,
252             nasty_deschedule_lock: unsafe { Mutex::new() },
253         }
254     }
255
256     pub fn give_home(&mut self, new_home: SchedHome) {
257         match self.task_type {
258             GreenTask(ref mut home) => {
259                 *home = Some(new_home);
260             }
261             SchedTask => {
262                 rtabort!("type error: used SchedTask as GreenTask");
263             }
264         }
265     }
266
267     pub fn take_unwrap_home(&mut self) -> SchedHome {
268         match self.task_type {
269             GreenTask(ref mut home) => {
270                 let out = home.take_unwrap();
271                 return out;
272             }
273             SchedTask => {
274                 rtabort!("type error: used SchedTask as GreenTask");
275             }
276         }
277     }
278
279     pub fn run(&mut self, f: ||) {
280         rtdebug!("run called on task: {}", borrow::to_uint(self));
281
282         // The only try/catch block in the world. Attempt to run the task's
283         // client-specified code and catch any failures.
284         self.unwinder.try(|| {
285
286             // Run the task main function, then do some cleanup.
287             f.finally(|| {
288
289                 // First, destroy task-local storage. This may run user dtors.
290                 //
291                 // FIXME #8302: Dear diary. I'm so tired and confused.
292                 // There's some interaction in rustc between the box
293                 // annihilator and the TLS dtor by which TLS is
294                 // accessed from annihilated box dtors *after* TLS is
295                 // destroyed. Somehow setting TLS back to null, as the
296                 // old runtime did, makes this work, but I don't currently
297                 // understand how. I would expect that, if the annihilator
298                 // reinvokes TLS while TLS is uninitialized, that
299                 // TLS would be reinitialized but never destroyed,
300                 // but somehow this works. I have no idea what's going
301                 // on but this seems to make things magically work. FML.
302                 //
303                 // (added after initial comment) A possible interaction here is
304                 // that the destructors for the objects in TLS themselves invoke
305                 // TLS, or possibly some destructors for those objects being
306                 // annihilated invoke TLS. Sadly these two operations seemed to
307                 // be intertwined, and miraculously work for now...
308                 self.storage.take();
309
310                 // Destroy remaining boxes. Also may run user dtors.
311                 unsafe { cleanup::annihilate(); }
312
313                 // Finally flush and destroy any output handles which the task
314                 // owns. There are no boxes here, and no user destructors should
315                 // run after this any more.
316                 match self.stdout_handle.take() {
317                     Some(handle) => {
318                         let mut handle = handle;
319                         handle.flush();
320                     }
321                     None => {}
322                 }
323                 self.logger.take();
324             })
325         });
326
327         // Cleanup the dynamic borrowck debugging info
328         borrowck::clear_task_borrow_list();
329
330         self.death.collect_failure(self.unwinder.to_unwind_result());
331         self.destroyed = true;
332     }
333
334     // New utility functions for homes.
335
336     pub fn is_home_no_tls(&self, sched: &~Scheduler) -> bool {
337         match self.task_type {
338             GreenTask(Some(AnySched)) => { false }
339             GreenTask(Some(Sched(SchedHandle { sched_id: ref id, .. }))) => {
340                 *id == sched.sched_id()
341             }
342             GreenTask(None) => {
343                 rtabort!("task without home");
344             }
345             SchedTask => {
346                 // Awe yea
347                 rtabort!("type error: expected: GreenTask, found: SchedTask");
348             }
349         }
350     }
351
352     pub fn homed(&self) -> bool {
353         match self.task_type {
354             GreenTask(Some(AnySched)) => { false }
355             GreenTask(Some(Sched(SchedHandle { .. }))) => { true }
356             GreenTask(None) => {
357                 rtabort!("task without home");
358             }
359             SchedTask => {
360                 rtabort!("type error: expected: GreenTask, found: SchedTask");
361             }
362         }
363     }
364
365     // Grab both the scheduler and the task from TLS and check if the
366     // task is executing on an appropriate scheduler.
367     pub fn on_appropriate_sched() -> bool {
368         let mut task = Local::borrow(None::<Task>);
369         let sched_id = task.get().sched.get_ref().sched_id();
370         let sched_run_anything = task.get().sched.get_ref().run_anything;
371         match task.get().task_type {
372             GreenTask(Some(AnySched)) => {
373                 rtdebug!("anysched task in sched check ****");
374                 sched_run_anything
375             }
376             GreenTask(Some(Sched(SchedHandle { sched_id: ref id, ..}))) => {
377                 rtdebug!("homed task in sched check ****");
378                 *id == sched_id
379             }
380             GreenTask(None) => {
381                 rtabort!("task without home");
382             }
383             SchedTask => {
384                 rtabort!("type error: expected: GreenTask, found: SchedTask");
385             }
386         }
387     }
388 }
389
390 impl Drop for Task {
391     fn drop(&mut self) {
392         rtdebug!("called drop for a task: {}", borrow::to_uint(self));
393         rtassert!(self.destroyed);
394
395         unsafe { self.nasty_deschedule_lock.destroy(); }
396     }
397 }
398
399 // Coroutines represent nothing more than a context and a stack
400 // segment.
401
402 impl Coroutine {
403
404     pub fn new(stack_pool: &mut StackPool,
405                stack_size: Option<uint>,
406                start: proc())
407                -> Coroutine {
408         let stack_size = match stack_size {
409             Some(size) => size,
410             None => env::min_stack()
411         };
412         let start = Coroutine::build_start_wrapper(start);
413         let mut stack = stack_pool.take_segment(stack_size);
414         let initial_context = Context::new(start, &mut stack);
415         Coroutine {
416             current_stack_segment: stack,
417             saved_context: initial_context
418         }
419     }
420
421     pub fn empty() -> Coroutine {
422         Coroutine {
423             current_stack_segment: StackSegment::new(0),
424             saved_context: Context::empty()
425         }
426     }
427
428     fn build_start_wrapper(start: proc()) -> proc() {
429         let wrapper: proc() = proc() {
430             // First code after swap to this new context. Run our
431             // cleanup job.
432             unsafe {
433
434                 // Again - might work while safe, or it might not.
435                 {
436                     let mut sched = Local::borrow(None::<Scheduler>);
437                     sched.get().run_cleanup_job();
438                 }
439
440                 // To call the run method on a task we need a direct
441                 // reference to it. The task is in TLS, so we can
442                 // simply unsafe_borrow it to get this reference. We
443                 // need to still have the task in TLS though, so we
444                 // need to unsafe_borrow.
445                 let task: *mut Task = Local::unsafe_borrow();
446
447                 let mut start_cell = Some(start);
448                 (*task).run(|| {
449                     // N.B. Removing `start` from the start wrapper
450                     // closure by emptying a cell is critical for
451                     // correctness. The ~Task pointer, and in turn the
452                     // closure used to initialize the first call
453                     // frame, is destroyed in the scheduler context,
454                     // not task context. So any captured closures must
455                     // not contain user-definable dtors that expect to
456                     // be in task context. By moving `start` out of
457                     // the closure, all the user code goes our of
458                     // scope while the task is still running.
459                     let start = start_cell.take_unwrap();
460                     start();
461                 });
462             }
463
464             // We remove the sched from the Task in TLS right now.
465             let sched: ~Scheduler = Local::take();
466             // ... allowing us to give it away when performing a
467             // scheduling operation.
468             sched.terminate_current_task()
469         };
470         return wrapper;
471     }
472
473     /// Destroy coroutine and try to reuse stack segment.
474     pub fn recycle(self, stack_pool: &mut StackPool) {
475         match self {
476             Coroutine { current_stack_segment, .. } => {
477                 stack_pool.give_segment(current_stack_segment);
478             }
479         }
480     }
481
482 }
483
484
485 // Just a sanity check to make sure we are catching a Rust-thrown exception
486 static UNWIND_TOKEN: uintptr_t = 839147;
487
488 impl Unwinder {
489     pub fn try(&mut self, f: ||) {
490         use unstable::raw::Closure;
491
492         unsafe {
493             let closure: Closure = transmute(f);
494             let code = transmute(closure.code);
495             let env = transmute(closure.env);
496
497             let token = rust_try(try_fn, code, env);
498             assert!(token == 0 || token == UNWIND_TOKEN);
499         }
500
501         extern fn try_fn(code: *c_void, env: *c_void) {
502             unsafe {
503                 let closure: Closure = Closure {
504                     code: transmute(code),
505                     env: transmute(env),
506                 };
507                 let closure: || = transmute(closure);
508                 closure();
509             }
510         }
511
512         extern {
513             fn rust_try(f: extern "C" fn(*c_void, *c_void),
514                         code: *c_void,
515                         data: *c_void) -> uintptr_t;
516         }
517     }
518
519     pub fn begin_unwind(&mut self, cause: ~Any) -> ! {
520         self.unwinding = true;
521         self.cause = Some(cause);
522         unsafe {
523             rust_begin_unwind(UNWIND_TOKEN);
524             return transmute(());
525         }
526         extern {
527             fn rust_begin_unwind(token: uintptr_t);
528         }
529     }
530 }
531
532 /// This function is invoked from rust's current __morestack function. Segmented
533 /// stacks are currently not enabled as segmented stacks, but rather one giant
534 /// stack segment. This means that whenever we run out of stack, we want to
535 /// truly consider it to be stack overflow rather than allocating a new stack.
536 #[no_mangle]      // - this is called from C code
537 #[no_split_stack] // - it would be sad for this function to trigger __morestack
538 #[doc(hidden)]    // - Function must be `pub` to get exported, but it's
539                   //   irrelevant for documentation purposes.
540 #[cfg(not(test))] // in testing, use the original libstd's version
541 pub extern "C" fn rust_stack_exhausted() {
542     use rt::in_green_task_context;
543     use rt::task::Task;
544     use rt::local::Local;
545     use unstable::intrinsics;
546
547     unsafe {
548         // We're calling this function because the stack just ran out. We need
549         // to call some other rust functions, but if we invoke the functions
550         // right now it'll just trigger this handler being called again. In
551         // order to alleviate this, we move the stack limit to be inside of the
552         // red zone that was allocated for exactly this reason.
553         let limit = context::get_sp_limit();
554         context::record_sp_limit(limit - context::RED_ZONE / 2);
555
556         // This probably isn't the best course of action. Ideally one would want
557         // to unwind the stack here instead of just aborting the entire process.
558         // This is a tricky problem, however. There's a few things which need to
559         // be considered:
560         //
561         //  1. We're here because of a stack overflow, yet unwinding will run
562         //     destructors and hence arbitrary code. What if that code overflows
563         //     the stack? One possibility is to use the above allocation of an
564         //     extra 10k to hope that we don't hit the limit, and if we do then
565         //     abort the whole program. Not the best, but kind of hard to deal
566         //     with unless we want to switch stacks.
567         //
568         //  2. LLVM will optimize functions based on whether they can unwind or
569         //     not. It will flag functions with 'nounwind' if it believes that
570         //     the function cannot trigger unwinding, but if we do unwind on
571         //     stack overflow then it means that we could unwind in any function
572         //     anywhere. We would have to make sure that LLVM only places the
573         //     nounwind flag on functions which don't call any other functions.
574         //
575         //  3. The function that overflowed may have owned arguments. These
576         //     arguments need to have their destructors run, but we haven't even
577         //     begun executing the function yet, so unwinding will not run the
578         //     any landing pads for these functions. If this is ignored, then
579         //     the arguments will just be leaked.
580         //
581         // Exactly what to do here is a very delicate topic, and is possibly
582         // still up in the air for what exactly to do. Some relevant issues:
583         //
584         //  #3555 - out-of-stack failure leaks arguments
585         //  #3695 - should there be a stack limit?
586         //  #9855 - possible strategies which could be taken
587         //  #9854 - unwinding on windows through __morestack has never worked
588         //  #2361 - possible implementation of not using landing pads
589
590         if in_green_task_context() {
591             let mut task = Local::borrow(None::<Task>);
592             let n = task.get()
593                         .name
594                         .as_ref()
595                         .map(|n| n.as_slice())
596                         .unwrap_or("<unnamed>");
597
598             // See the message below for why this is not emitted to the
599             // task's logger. This has the additional conundrum of the
600             // logger may not be initialized just yet, meaning that an FFI
601             // call would happen to initialized it (calling out to libuv),
602             // and the FFI call needs 2MB of stack when we just ran out.
603             rterrln!("task '{}' has overflowed its stack", n);
604         } else {
605             rterrln!("stack overflow in non-task context");
606         }
607
608         intrinsics::abort();
609     }
610 }
611
612 /// This is the entry point of unwinding for things like lang items and such.
613 /// The arguments are normally generated by the compiler, and need to
614 /// have static lifetimes.
615 pub fn begin_unwind_raw(msg: *c_char, file: *c_char, line: size_t) -> ! {
616     use c_str::CString;
617     use cast::transmute;
618
619     #[inline]
620     fn static_char_ptr(p: *c_char) -> &'static str {
621         let s = unsafe { CString::new(p, false) };
622         match s.as_str() {
623             Some(s) => unsafe { transmute::<&str, &'static str>(s) },
624             None => rtabort!("message wasn't utf8?")
625         }
626     }
627
628     let msg = static_char_ptr(msg);
629     let file = static_char_ptr(file);
630
631     begin_unwind(msg, file, line as uint)
632 }
633
634 /// This is the entry point of unwinding for fail!() and assert!().
635 pub fn begin_unwind<M: Any + Send>(msg: M, file: &'static str, line: uint) -> ! {
636     use any::AnyRefExt;
637     use rt::in_green_task_context;
638     use rt::local::Local;
639     use rt::task::Task;
640     use str::Str;
641     use unstable::intrinsics;
642
643     unsafe {
644         let task: *mut Task;
645         // Note that this should be the only allocation performed in this block.
646         // Currently this means that fail!() on OOM will invoke this code path,
647         // but then again we're not really ready for failing on OOM anyway. If
648         // we do start doing this, then we should propagate this allocation to
649         // be performed in the parent of this task instead of the task that's
650         // failing.
651         let msg = ~msg as ~Any;
652
653         {
654             //let msg: &Any = msg;
655             let msg_s = match msg.as_ref::<&'static str>() {
656                 Some(s) => *s,
657                 None => match msg.as_ref::<~str>() {
658                     Some(s) => s.as_slice(),
659                     None => "~Any",
660                 }
661             };
662
663             if !in_green_task_context() {
664                 rterrln!("failed in non-task context at '{}', {}:{}",
665                          msg_s, file, line);
666                 intrinsics::abort();
667             }
668
669             task = Local::unsafe_borrow();
670             let n = (*task).name.as_ref().map(|n| n.as_slice()).unwrap_or("<unnamed>");
671
672             // XXX: this should no get forcibly printed to the console, this should
673             //      either be sent to the parent task (ideally), or get printed to
674             //      the task's logger. Right now the logger is actually a uvio
675             //      instance, which uses unkillable blocks internally for various
676             //      reasons. This will cause serious trouble if the task is failing
677             //      due to mismanagment of its own kill flag, so calling our own
678             //      logger in its current state is a bit of a problem.
679
680             rterrln!("task '{}' failed at '{}', {}:{}", n, msg_s, file, line);
681
682             if (*task).unwinder.unwinding {
683                 rtabort!("unwinding again");
684             }
685         }
686
687         (*task).unwinder.begin_unwind(msg);
688     }
689 }
690
691 #[cfg(test)]
692 mod test {
693     use super::*;
694     use rt::test::*;
695
696     #[test]
697     fn local_heap() {
698         do run_in_newsched_task() {
699             let a = @5;
700             let b = a;
701             assert!(*a == 5);
702             assert!(*b == 5);
703         }
704     }
705
706     #[test]
707     fn tls() {
708         use local_data;
709         do run_in_newsched_task() {
710             local_data_key!(key: @~str)
711             local_data::set(key, @~"data");
712             assert!(*local_data::get(key, |k| k.map(|k| *k)).unwrap() == ~"data");
713             local_data_key!(key2: @~str)
714             local_data::set(key2, @~"data");
715             assert!(*local_data::get(key2, |k| k.map(|k| *k)).unwrap() == ~"data");
716         }
717     }
718
719     #[test]
720     fn unwind() {
721         do run_in_newsched_task() {
722             let result = spawntask_try(proc()());
723             rtdebug!("trying first assert");
724             assert!(result.is_ok());
725             let result = spawntask_try(proc() fail!());
726             rtdebug!("trying second assert");
727             assert!(result.is_err());
728         }
729     }
730
731     #[test]
732     fn rng() {
733         do run_in_uv_task() {
734             use rand::{rng, Rng};
735             let mut r = rng();
736             let _ = r.next_u32();
737         }
738     }
739
740     #[test]
741     fn logging() {
742         do run_in_uv_task() {
743             info!("here i am. logging in a newsched task");
744         }
745     }
746
747     #[test]
748     fn comm_oneshot() {
749         use comm::*;
750
751         do run_in_newsched_task {
752             let (port, chan) = oneshot();
753             chan.send(10);
754             assert!(port.recv() == 10);
755         }
756     }
757
758     #[test]
759     fn comm_stream() {
760         use comm::*;
761
762         do run_in_newsched_task() {
763             let (port, chan) = stream();
764             chan.send(10);
765             assert!(port.recv() == 10);
766         }
767     }
768
769     #[test]
770     fn comm_shared_chan() {
771         use comm::*;
772
773         do run_in_newsched_task() {
774             let (port, chan) = stream();
775             let chan = SharedChan::new(chan);
776             chan.send(10);
777             assert!(port.recv() == 10);
778         }
779     }
780
781     #[test]
782     fn heap_cycles() {
783         use option::{Option, Some, None};
784
785         do run_in_newsched_task {
786             struct List {
787                 next: Option<@mut List>,
788             }
789
790             let a = @mut List { next: None };
791             let b = @mut List { next: Some(a) };
792
793             a.next = Some(b);
794         }
795     }
796
797     #[test]
798     #[should_fail]
799     fn test_begin_unwind() { begin_unwind("cause", file!(), line!()) }
800 }