about summary refs log tree commit diff
path: root/src/libstd/rt/task.rs
AgeCommit message (Collapse)AuthorLines
2014-02-18Spellcheck library docs.Huon Wilson-1/+1
2014-02-13Don't require an allocation for on_exit messagesAlex Crichton-4/+12
Instead, use an enum to allow running both a procedure and sending the task result over a channel. I expect the common case to be sending on a channel (e.g. task::try), so don't require an extra allocation in the common case. cc #11389
2014-02-11Rewrite channels yet again for upgradeabilityAlex Crichton-1/+1
This, the Nth rewrite of channels, is not a rewrite of the core logic behind channels, but rather their API usage. In the past, we had the distinction between oneshot, stream, and shared channels, but the most recent rewrite dropped oneshots in favor of streams and shared channels. This distinction of stream vs shared has shown that it's not quite what we'd like either, and this moves the `std::comm` module in the direction of "one channel to rule them all". There now remains only one Chan and one Port. This new channel is actually a hybrid oneshot/stream/shared channel under the hood in order to optimize for the use cases in question. Additionally, this also reduces the cognitive burden of having to choose between a Chan or a SharedChan in an API. My simple benchmarks show no reduction in efficiency over the existing channels today, and a 3x improvement in the oneshot case. I sadly don't have a pre-last-rewrite compiler to test out the old old oneshots, but I would imagine that the performance is comparable, but slightly slower (due to atomic reference counting). This commit also brings the bonus bugfix to channels that the pending queue of messages are all dropped when a Port disappears rather then when both the Port and the Chan disappear.
2014-02-07Delete send_str, rewrite clients on top of MaybeOwned<'static>Kevin Ballard-1/+1
Declare a `type SendStr = MaybeOwned<'static>` to ease readibility of types that needed the old SendStr behavior. Implement all the traits for MaybeOwned that SendStr used to implement.
2014-02-03std: Remove try_send_deferred plus all falloutAlex Crichton-2/+8
Now that extra::sync primitives are built on a proper mutex instead of a pthreads one, there's no longer any use for this function.
2014-02-03std: Remove io::io_errorAlex Crichton-2/+3
* All I/O now returns IoResult<T> = Result<T, IoError> * All formatting traits now return fmt::Result = IoResult<()> * The if_ok!() macro was added to libstd
2014-01-29Remove seldom-used std::reference functions.xales-2/+1
2014-01-29Rename std::borrow to std::reference.xales-2/+2
Fixes #11814
2014-01-26Removed all instances of XXX in preparation for relaxing of FIXME ruleSalem Talha-1/+1
2014-01-21Purge borrowck from libstdAlex Crichton-8/+0
This hasn't been in use since `@mut` was removed
2014-01-18Rename iterators for consistencyPalmer Cox-4/+4
Rename existing iterators to get rid of the Iterator suffix and to give them names that better describe the things being iterated over.
2014-01-16Fix some docs in std::rt::taskDerek Chiang-7/+6
2014-01-09auto merge of #11360 : huonw/rust/stack_bounds, r=alexcrichtonbors-1/+1
We just approximate with a 2MB stack for native::start.
2014-01-07std: Fill in all missing importsAlex Crichton-0/+1
Fallout from the previous commits
2014-01-07auto merge of #11353 : alexcrichton/rust/improve-logging, r=brsonbors-19/+25
This will allow capturing of common things like logging messages, stdout prints (using stdio println), and failure messages (printed to stderr). Any new prints added to libstd should be funneled through these task handles to allow capture as well. Additionally, this commit redirects logging back through a `Logger` trait so the log level can be usefully consumed by an arbitrary logger. This commit also introduces methods to set the task-local stdout handles: * std::io::stdio::set_stdout * std::io::stdio::set_stderr * std::io::logging::set_logger These methods all return the previous logger just in case it needs to be used for inspection. I plan on using this infrastructure for extra::test soon, but we don't quite have the primitives that I'd like to use for it, so it doesn't migrate extra::test at this time. Closes #6369
2014-01-07std::rt: require known stack bounds for all tasks.Huon Wilson-1/+1
We just approximate with a 1 or 2 MB stack for native::start.
2014-01-06Support arbitrary stdout/stderr/logger handlesAlex Crichton-19/+25
This will allow capturing of common things like logging messages, stdout prints (using stdio println), and failure messages (printed to stderr). Any new prints added to libstd should be funneled through these task handles to allow capture as well. Additionally, this commit redirects logging back through a `Logger` trait so the log level can be usefully consumed by an arbitrary logger. This commit also introduces methods to set the task-local stdout handles: * std::io::stdio::set_stdout * std::io::stdio::set_stderr * std::io::logging::set_logger These methods all return the previous logger just in case it needs to be used for inspection. I plan on using this infrastructure for extra::test soon, but we don't quite have the primitives that I'd like to use for it, so it doesn't migrate extra::test at this time. Closes #6369
2014-01-06Register new snapshotsAlex Crichton-3/+0
2014-01-04Don't allow newtype structs to be dereferenced. #6246Brian Anderson-2/+6
2014-01-04auto merge of #11306 : alexcrichton/rust/native-bounds, r=pcwaltonbors-0/+7
This allows inspection of the current task's bounds regardless of what the underlying task is. Closes #11293
2014-01-04Add a stack_bounds function to the Runtime traitAlex Crichton-0/+7
This allows inspection of the current task's bounds regardless of what the underlying task is. Closes #11293
2014-01-03libstd: De-`@mut` the `heap_cycles` testPatrick Walton-4/+8
2014-01-01Move task count bookeeping out of libstdAlex Crichton-32/+1
For libgreen, bookeeping should not be global but rather on a per-pool basis. Inside libnative, it's known that there must be a global counter with a mutex/cvar. The benefit of taking this strategy is to remove this functionality from libstd to allow fine-grained control of it through libnative/libgreen. Notably, helper threads in libnative can manually decrement the global count so they don't count towards the global count of threads. Also, the shutdown process of *all* sched pools is now dependent on the number of tasks in the pool being 0 rather than this only being a hardcoded solution for the initial sched pool in libgreen. This involved adding a Local::try_take() method on the Local trait in order for the channel wakeup to work inside of libgreen. The channel send was happening from a SchedTask when there is no Task available in TLS, and now this is possible to work (remote wakeups are always possible, just a little slower).
2013-12-25Test fixes and rebase conflictsAlex Crichton-2/+6
* vec::raw::to_ptr is gone * Pausible => Pausable * Removing @ * Calling the main task "<main>" * Removing unused imports * Removing unused mut * Bringing some libextra tests up to date * Allowing compiletest to work at stage0 * Fixing the bootstrap-from-c rmake tests * assert => rtassert in a few cases * printing to stderr instead of stdout in fail!()
2013-12-24green: Properly wait for main before shutdownAlex Crichton-12/+15
There was a race in the code previously where schedulers would *immediately* shut down after spawning the main task (because the global task count would still be 0). This fixes the logic by blocking the sched pool task in receving on a port instead of spawning a task into the pool to receive on a port. The modifications necessary were to have a "simple task" running by the time the code is executing, but this is a simple enough thing to implement and I forsee this being necessary to have implemented in the future anyway.
2013-12-24Test fixes and rebase problemsAlex Crichton-2/+16
Note that this removes a number of run-pass tests which are exercising behavior of the old runtime. This functionality no longer exists and is thoroughly tested inside of libgreen and libnative. There isn't really the notion of "starting the runtime" any more. The major notion now is "bootstrapping the initial task".
2013-12-24Finalize the green::Pool typeAlex Crichton-1/+19
The scheduler pool now has a much more simplified interface. There is now a clear distinction between creating the pool and then interacting the pool. When a pool is created, all schedulers are not active, and only later if a spawn is done does activity occur. There are four operations that you can do on a pool: 1. Create a new pool. The only argument to this function is the configuration for the scheduler pool. Currently the only configuration parameter is the number of threads to initially spawn. 2. Spawn a task into this pool. This takes a procedure and task configuration options and spawns a new task into the pool of schedulers. 3. Spawn a new scheduler into the pool. This will return a handle on which to communicate with the scheduler in order to do something like a pinned task. 4. Shut down the scheduler pool. This will consume the scheduler pool, request all of the schedulers to shut down, and then wait on all the scheduler threads. Currently this will block the invoking OS thread, but I plan on making 'Thread::join' not a thread-blocking call. These operations can be used to encode all current usage of M:N schedulers, as well as providing a simple interface through which a pool can be modified. There is currently no way to remove a scheduler from a pool of scheduler, as there's no way to guarantee that a scheduler has exited. This may be added in the future, however (as necessary).
2013-12-24std: Get stdtest all passing againAlex Crichton-53/+41
This commit brings the library up-to-date in order to get all tests passing again
2013-12-24green: Rip the bandaid off, introduce libgreenAlex Crichton-444/+229
This extracts everything related to green scheduling from libstd and introduces a new libgreen crate. This mostly involves deleting most of std::rt and moving it to libgreen. Along with the movement of code, this commit rearchitects many functions in the scheduler in order to adapt to the fact that Local::take now *only* works on a Task, not a scheduler. This mostly just involved threading the current green task through in a few locations, but there were one or two spots where things got hairy. There are a few repercussions of this commit: * tube/rc have been removed (the runtime implementation of rc) * There is no longer a "single threaded" spawning mode for tasks. This is now encompassed by 1:1 scheduling + communication. Convenience methods have been introduced that are specific to libgreen to assist in the spawning of pools of schedulers.
2013-12-24Stop using C++ exceptions for stack unwinding.Vadim Chugunov-66/+2
2013-12-20std: silence warnings when compiling test.Huon Wilson-1/+1
2013-12-16Fallout of rewriting std::commAlex Crichton-52/+10
2013-12-16Rewrite std::commAlex Crichton-1/+0
* Streams are now ~3x faster than before (fewer allocations and more optimized) * Based on a single-producer single-consumer lock-free queue that doesn't always have to allocate on every send. * Blocking via mutexes/cond vars outside the runtime * Streams work in/out of the runtime seamlessly * Select now works in/out of the runtime seamlessly * Streams will now fail!() on send() if the other end has hung up * try_send() will not fail * PortOne/ChanOne removed * SharedPort removed * MegaPipe removed * Generic select removed (only one kind of port now) * API redesign * try_recv == never block * recv_opt == block, don't fail * iter() == Iterator<T> for Port<T> * removed peek * Type::new * Removed rt::comm
2013-12-10libstd: Remove two uses of `Cell`.Patrick Walton-3/+2
2013-12-10librustuv: RAII-ify `Local::borrow`, and remove some 12 Cells.Patrick Walton-54/+52
2013-12-06Link rustllvm statically, and distribute a static snapshotAlex Crichton-0/+1
In order to keep up to date with changes to the libraries that `llvm-config` spits out, the dependencies to the LLVM are a dynamically generated rust file. This file is now automatically updated whenever LLVM is updated to get kept up-to-date. At the same time, this cleans out some old cruft which isn't necessary in the makefiles in terms of dependencies. Closes #10745 Closes #10744
2013-12-05Solve some nasty deschedulinging races with a lockAlex Crichton-0/+9
Right now, as pointed out in #8132, it is very easy to introduce a subtle race in the runtime. I believe that this is the cause of the current flakiness on the bots. I have taken the last idea mentioned in that issue which is to use a lock around descheduling and context switching in order to solve this race. Closes #8132
2013-11-28Register new snapshotsAlex Crichton-4/+4
2013-11-26librustc: Make `||` lambdas not infer to `proc`sPatrick Walton-3/+3
2013-11-26libstd: Remove all non-`proc` uses of `do` from libstdPatrick Walton-16/+16
2013-11-24Remove linked failure from the runtimeAlex Crichton-27/+3
The reasons for doing this are: * The model on which linked failure is based is inherently complex * The implementation is also very complex, and there are few remaining who fully understand the implementation * There are existing race conditions in the core context switching function of the scheduler, and possibly others. * It's unclear whether this model of linked failure maps well to a 1:1 threading model Linked failure is often a desired aspect of tasks, but we would like to take a much more conservative approach in re-implementing linked failure if at all. Closes #8674 Closes #8318 Closes #8863
2013-11-19libstd: Change all uses of `&fn(A)->B` over to `|A|->B` in libstdPatrick Walton-3/+3
2013-11-18libstd: Change all `~fn()`s to `proc`s in the standard library.Patrick Walton-11/+20
This makes `Cell`s no longer necessary in most cases.
2013-11-11Move std::rt::io to std::ioAlex Crichton-1/+1
2013-11-11Remove #[fixed_stack_segment] and #[rust_stack]Alex Crichton-6/+2
These two attributes are no longer useful now that Rust has decided to leave segmented stacks behind. It is assumed that the rust task's stack is always large enough to make an FFI call (due to the stack being very large). There's always the case of stack overflow, however, to consider. This does not change the behavior of stack overflow in Rust. This is still normally triggered by the __morestack function and aborts the whole process. C stack overflow will continue to corrupt the stack, however (as it did before this commit as well). The future improvement of a guard page at the end of every rust stack is still unimplemented and is intended to be the mechanism through which we attempt to detect C stack overflow. Closes #8822 Closes #10155
2013-11-10Clean up the remaining chunks of uvAlex Crichton-4/+5
2013-11-01Remove unnecessary unwind messagesAlex Crichton-53/+24
Now that the type_id intrinsic is working across crates, all of these unnecessary messages can be removed to have the failure type for a task truly be ~Any and only ~Any
2013-10-30Prepared `std::sys` for removal, and made `begin_unwind` simplerMarvin Löbel-19/+52
- `begin_unwind` is now generic over any `T: Any + Send`. - Every value you fail with gets boxed as an `~Any`. - Because of implementation details, `&'static str` and `~str` are still handled specially behind the scenes. - Changed the big macro source string in libsyntax to a raw string literal, and enabled doc comments there.
2013-10-28rt::task: Make current_stack_segment public againKeegan McAllister-1/+4
This was done in 2145de8c and reverted in 0ada7c7f, but Servo needs it. Closes #10065.
2013-10-28Allow fail messages to be caught, and introduce the Any traitMarvin Löbel-50/+124
Some code cleanup, sorting of import blocks Removed std::unstable::UnsafeArc's use of Either Added run-fail tests for the new FailWithCause impls Changed future_result and try to return Result<(), ~Any>. - Internally, there is an enum of possible fail messages passend around. - In case of linked failure or a string message, the ~Any gets lazyly allocated in future_results recv method. - For that, future result now returns a wrapper around a Port. - Moved and renamed task::TaskResult into rt::task::UnwindResult and made it an internal enum. - Introduced a replacement typedef `type TaskResult = Result<(), ~Any>`.