/src/test/run-pass/basic.rs

http://github.com/jruderman/rust · Rust · 55 lines · 48 code · 6 blank · 1 comment · 2 complexity · aa88a7d0296ae8da57030a10fd6e1b09 MD5 · raw file

  1. // -*- rust -*-
  2. use std;
  3. import comm;
  4. import comm::send;
  5. import comm::chan;
  6. import comm::recv;
  7. import task;
  8. fn a(c: chan<int>) {
  9. if true {
  10. debug!{"task a"};
  11. debug!{"task a"};
  12. debug!{"task a"};
  13. debug!{"task a"};
  14. debug!{"task a"};
  15. }
  16. send(c, 10);
  17. }
  18. fn k(x: int) -> int { return 15; }
  19. fn g(x: int, y: ~str) -> int {
  20. log(debug, x);
  21. log(debug, y);
  22. let z: int = k(1);
  23. return z;
  24. }
  25. fn main() {
  26. let mut n: int = 2 + 3 * 7;
  27. let s: ~str = ~"hello there";
  28. let p = comm::port();
  29. let ch = comm::chan(p);
  30. task::spawn(|| a(ch) );
  31. task::spawn(|| b(ch) );
  32. let mut x: int = 10;
  33. x = g(n, s);
  34. log(debug, x);
  35. n = recv(p);
  36. n = recv(p);
  37. debug!{"children finished, root finishing"};
  38. }
  39. fn b(c: chan<int>) {
  40. if true {
  41. debug!{"task b"};
  42. debug!{"task b"};
  43. debug!{"task b"};
  44. debug!{"task b"};
  45. debug!{"task b"};
  46. debug!{"task b"};
  47. }
  48. send(c, 10);
  49. }