Skip to content

Commit 3b09c3d

Browse files
committed
Document arc::unwrap. Close #3123.
1 parent 71ec545 commit 3b09c3d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/libstd/arc.rs

+22
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ fn clone<T: const send>(rc: &arc<T>) -> arc<T> {
9393
arc { x: unsafe { clone_shared_mutable_state(&rc.x) } }
9494
}
9595

96+
/**
97+
* Retrieve the data back out of the ARC. This function blocks until the
98+
* reference given to it is the last existing one, and then unwrap the data
99+
* instead of destroying it.
100+
*
101+
* If multiple tasks call unwrap, all but the first will fail. Do not call
102+
* unwrap from a task that holds another reference to the same ARC; it is
103+
* guaranteed to deadlock.
104+
*/
96105
fn unwrap<T: const send>(+rc: arc<T>) -> T {
97106
let arc { x: x } = rc;
98107
unsafe { unwrap_shared_mutable_state(x) }
@@ -186,6 +195,12 @@ impl<T: send> &mutex_arc<T> {
186195
}
187196
}
188197

198+
/**
199+
* Retrieves the data, blocking until all other references are dropped,
200+
* exactly as arc::unwrap.
201+
*
202+
* Will additionally fail if another task has failed while accessing the arc.
203+
*/
189204
// FIXME(#2585) make this a by-move method on the arc
190205
fn unwrap_mutex_arc<T: send>(+arc: mutex_arc<T>) -> T {
191206
let mutex_arc { x: x } = arc;
@@ -363,6 +378,13 @@ impl<T: const send> &rw_arc<T> {
363378
}
364379
}
365380
381+
/**
382+
* Retrieves the data, blocking until all other references are dropped,
383+
* exactly as arc::unwrap.
384+
*
385+
* Will additionally fail if another task has failed while accessing the arc
386+
* in write mode.
387+
*/
366388
// FIXME(#2585) make this a by-move method on the arc
367389
fn unwrap_rw_arc<T: const send>(+arc: rw_arc<T>) -> T {
368390
let rw_arc { x: x, _ } = arc;

0 commit comments

Comments
 (0)