Skip to content

Commit 0c623c4

Browse files
committed
Document arc::exclusive.
1 parent 241085a commit 0c623c4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/libcore/arc.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ fn exclusive<T:send >(-data: T) -> exclusive<T> {
9797
}
9898

9999
impl methods<T: send> for exclusive<T> {
100+
/// Duplicate an exclusive ARC. See arc::clone.
100101
fn clone() -> exclusive<T> {
101102
unsafe {
102103
// this makes me nervous...
@@ -109,6 +110,22 @@ impl methods<T: send> for exclusive<T> {
109110
arc_destruct(self.data)
110111
}
111112

113+
/**
114+
* Access the underlying mutable data with mutual exclusion from other
115+
* tasks. The argument closure will be run with the mutex locked; all
116+
* other tasks wishing to access the data will block until the closure
117+
* finishes running.
118+
*
119+
* Currently, scheduling operations (i.e., yielding, receiving on a pipe,
120+
* accessing the provided condition variable) are prohibited while inside
121+
* the exclusive. Supporting that is a work in progress.
122+
*
123+
* The reason this function is 'unsafe' is because it is possible to
124+
* construct a circular reference among multiple ARCs by mutating the
125+
* underlying data. This creates potential for deadlock, but worse, this
126+
* will guarantee a memory leak of all involved ARCs. Using exclusive
127+
* ARCs inside of other ARCs is safe in absence of circular references.
128+
*/
112129
unsafe fn with<U>(f: fn(sys::condition, x: &mut T) -> U) -> U {
113130
let ptr: ~arc_data<ex_data<T>> =
114131
unsafe::reinterpret_cast(self.data);

0 commit comments

Comments
 (0)