From 3b09c3deaa9a376d0ae40a783713ece3720ca08f Mon Sep 17 00:00:00 2001 From: Ben Blum Date: Mon, 20 Aug 2012 22:30:53 -0400 Subject: [PATCH] Document arc::unwrap. Close #3123. --- src/libstd/arc.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/libstd/arc.rs b/src/libstd/arc.rs index 531140c7e48d..355567e07e2a 100644 --- a/src/libstd/arc.rs +++ b/src/libstd/arc.rs @@ -93,6 +93,15 @@ fn clone(rc: &arc) -> arc { 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(+rc: arc) -> T { let arc { x: x } = rc; unsafe { unwrap_shared_mutable_state(x) } @@ -186,6 +195,12 @@ impl &mutex_arc { } } +/** + * 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(+arc: mutex_arc) -> T { let mutex_arc { x: x } = arc; @@ -363,6 +378,13 @@ impl &rw_arc { } } +/** + * 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(+arc: rw_arc) -> T { let rw_arc { x: x, _ } = arc;