Weitere ähnliche Inhalte Ähnlich wie Rustのタスクモデルについて (20) Rustのタスクモデルについて17. “A pipe is simply
a pair of endpoints”
13年9月7日土曜日
21. 実際にやってみる
use std : : task;
let (port , chan) : (Port<int>, Chan<int>) = stream( );
do spawn | arg | {
chan . send (arg);
}
13年9月7日土曜日
22. 実際にやってみる
use std : : task;
let (port , chan) : (Port<int>, Chan<int>) = stream( );
do spawn | arg | {
chan . send (arg);
}
型宣言
13年9月7日土曜日
23. 実際にやってみる
use std : : task;
let (port , chan) : (Port<int>, Chan<int>) = stream( );
do spawn | arg | {
chan . send (arg);
}
型宣言
argはport . recv()で取得できる
13年9月7日土曜日
25. 例えば
let (port , chan) = stream( );
do spawn | arg1 | {
chan . send (arg1);
}
do spawn | arg2 | {
chan . send (arg2);
}
13年9月7日土曜日
26. `chan` moved into closure
environment here
because it has type `~fn:Send( )`,
which is non-copyable
(perhaps you meant to use clone( )? )
error: aborting due to previous error
13年9月7日土曜日
30. use std : : comm;
let (port , chan) = comm : : stream( );
13年9月7日土曜日
31. use std : : comm;
let (port , chan) = comm : : stream( );
let chan = comm : : SharedChan : : new(chan);
13年9月7日土曜日
32. use std : : comm;
let (port , chan) = comm : : stream( );
let chan = comm : : SharedChan : : new(chan);
chanを上書きする
13年9月7日土曜日
33. use std : : comm;
let (port , chan) = comm : : stream( );
let chan = comm : : SharedChan : : new(chan);
do spawn | hoge | {
let child_chan = chan . clone( );
child_chan.send(arg);
}
13年9月7日土曜日
34. use std : : comm;
let (port , chan) = comm : : stream( );
let chan = comm : : SharedChan : : new(chan);
do spawn | hoge | {
let child_chan = chan . clone( );
child_chan.send(arg);
}
タスク内でclone( )する
13年9月7日土曜日
40. extern mod extra;
use extra : : arc : :Arc;
let (port , chan) = stream( );
let pi = 3.14159;
let shared_num = Arc : : new(num);
13年9月7日土曜日
41. extern mod extra;
use extra : : arc : :Arc;
let (port , chan) = stream( );
let pi = 3.14159;
let shared_num = Arc : : new(num);
do spawn {
let local_num :Arc<float> = port.recv();
println( fmt!( " % ? ", local_num . get( )));
}
13年9月7日土曜日
44. “exceptions in Rust are
unrecoverable within a single task:
once a task fails, there is no way to
"catch" the exception.”
http://static.rust-lang.org/doc/tutorial-tasks.html
13年9月7日土曜日
47. let result : Result<( ) , ( )> = do task : : try {
fail( );
};
assert!(result . is_err( ));
13年9月7日土曜日