diff options
| author | Ben Blum <bblum@andrew.cmu.edu> | 2012-08-20 22:30:53 -0400 |
|---|---|---|
| committer | Ben Blum <bblum@andrew.cmu.edu> | 2012-08-20 22:31:17 -0400 |
| commit | 3b09c3deaa9a376d0ae40a783713ece3720ca08f (patch) | |
| tree | fc80cb0bd03c58583c177ad7e3295b4793a01e5c /src | |
| parent | 71ec545614e72b815a3685bb461c7853368b92b0 (diff) | |
Document arc::unwrap. Close #3123.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libstd/arc.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libstd/arc.rs b/src/libstd/arc.rs index 531140c7e48..355567e07e2 100644 --- a/src/libstd/arc.rs +++ b/src/libstd/arc.rs @@ -93,6 +93,15 @@ fn clone<T: const send>(rc: &arc<T>) -> arc<T> { arc { x: unsafe { clone_shared_mutable_state(&rc.x) } } } +/** + * Retrieve the data back out of the ARC. This function blocks until the + * reference given to it is the last existing one, and then unwrap the data + * instead of destroying it. + * + * If multiple tasks call unwrap, all but the first will fail. Do not call + * unwrap from a task that holds another reference to the same ARC; it is + * guaranteed to deadlock. + */ fn unwrap<T: const send>(+rc: arc<T>) -> T { let arc { x: x } = rc; unsafe { unwrap_shared_mutable_state(x) } @@ -186,6 +195,12 @@ impl<T: send> &mutex_arc<T> { } } +/** + * Retrieves the data, blocking until all other references are dropped, + * exactly as arc::unwrap. + * + * Will additionally fail if another task has failed while accessing the arc. + */ // FIXME(#2585) make this a by-move method on the arc fn unwrap_mutex_arc<T: send>(+arc: mutex_arc<T>) -> T { let mutex_arc { x: x } = arc; @@ -363,6 +378,13 @@ impl<T: const send> &rw_arc<T> { } } +/** + * Retrieves the data, blocking until all other references are dropped, + * exactly as arc::unwrap. + * + * Will additionally fail if another task has failed while accessing the arc + * in write mode. + */ // FIXME(#2585) make this a by-move method on the arc fn unwrap_rw_arc<T: const send>(+arc: rw_arc<T>) -> T { let rw_arc { x: x, _ } = arc; |
