diff options
| author | Ben Blum <bblum@andrew.cmu.edu> | 2012-08-03 17:50:47 -0400 |
|---|---|---|
| committer | Ben Blum <bblum@andrew.cmu.edu> | 2012-08-03 17:50:59 -0400 |
| commit | 0c623c4474f439c0bb85b7f91ae663d9584e7973 (patch) | |
| tree | 6163466b724449f047cb93db19312f67e827f2e4 /src | |
| parent | 241085a073805447c0ad1b55525faaddcd00bedc (diff) | |
Document arc::exclusive.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/arc.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libcore/arc.rs b/src/libcore/arc.rs index 30bed71aa95..d382ca55e0b 100644 --- a/src/libcore/arc.rs +++ b/src/libcore/arc.rs @@ -97,6 +97,7 @@ fn exclusive<T:send >(-data: T) -> exclusive<T> { } impl methods<T: send> for exclusive<T> { + /// Duplicate an exclusive ARC. See arc::clone. fn clone() -> exclusive<T> { unsafe { // this makes me nervous... @@ -109,6 +110,22 @@ impl methods<T: send> for exclusive<T> { arc_destruct(self.data) } + /** + * Access the underlying mutable data with mutual exclusion from other + * tasks. The argument closure will be run with the mutex locked; all + * other tasks wishing to access the data will block until the closure + * finishes running. + * + * Currently, scheduling operations (i.e., yielding, receiving on a pipe, + * accessing the provided condition variable) are prohibited while inside + * the exclusive. Supporting that is a work in progress. + * + * The reason this function is 'unsafe' is because it is possible to + * construct a circular reference among multiple ARCs by mutating the + * underlying data. This creates potential for deadlock, but worse, this + * will guarantee a memory leak of all involved ARCs. Using exclusive + * ARCs inside of other ARCs is safe in absence of circular references. + */ unsafe fn with<U>(f: fn(sys::condition, x: &mut T) -> U) -> U { let ptr: ~arc_data<ex_data<T>> = unsafe::reinterpret_cast(self.data); |
