I've been spending the last week or so working on moving the task and 
communication system to a library (Issue #531). Yesterday I committed changes 
that remove support for the spawn primitive and the task type from the 
compiler. Before long I'll do the same with the send and receive operators, as 
well as the port and chan related primitives. Here's a summary of the changes, 
how to use the new system, things that will be changing, and caveats.

 * Spawn has been removed. Use std::task::_spawn instead, although this will be 
renamed to std::task::spawn soon. Spawn takes a thunk, so what previously would 
have been `spawn foo(1, 2, 3)` will usually become `_spawn(bind foo(1, 2, 3))`.

 * task::join is replaced with task::join_id. task::join will come back soon 
though.

 * Ports are replaced with the std::comm::_port data type (which will be 
renamed port). You make one using std::comm::mk_port[T](). Ports are currently 
objects (although this will be changing too), so you receive from a port by 
doing `p.recv()`.

 * Chans have been replaced with the std::comm::_chan data type (again, to be 
renamed just chan). You make one from a port by doing `p.mk_chan()`. Send using 
std::comm::send, such as `send(c, 42)`. Chans are represented internally as a 
pair of a task id and a port id, so they're really easy to send over channels 
now.

 * Chans and ports have a kind restriction, they can only be made for unique 
kinded types. Send uses move-mode, which deinitializes whatever you send. This 
means you need to make sure to copy the thing you're sending if you want to use 
it again. Fortunately, in practice we seem to mostly send temporaries, so this 
isn't a big deal.

 * Spawn should have a kind restriction but does not currently. Be careful what 
you put in its closure. In particular, if you close over strings, you will 
probably leak memory. For this cause, use [u8] instead.

 * Overall, the system feels more robust now. A lot of weird memory issues I 
had been seeing before seem to have basically disappeared (largely due to 
move-mode and the kind restriction, I suspect).

 * There's currently a race condition in task::join_id that means you can't 
reliably get the exit status if you join a task after it has already 
terminated. This shows up most often as run-pass tests failing but not being 
detected or compile-fail tests successfully failing but reporting success 
instead. Fortunately, when something goes wrong, we leak memory which other 
parts of our runtime catch, so a failure still fails the test run.

 * A few parts of the system are a bit clunky (for example, prefixing 
everything with underscores). I'll be working on making this look a little 
nicer. Since it's in a library and easy enough to do this, I'll try to maintain 
backward compatibility so we don't have to rewrite all our task/comm code every 
time I make a change. The old versions will probably be marked as deprecated 
somehow (#[deprecated]?) and then removed at some point.

Please try out the new system, ask questions, make comments, etc.

-Eric
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to