wrc 0.1.0

A thread-safe weighted reference counting smart-pointer for Rust.
docs.rs failed to build wrc-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: wrc-2.0.0

WRC

A thread-safe weighted reference counting smart-pointer for Rust.

Overview

By using weights instead of direct reference counting WRC requires roughly half as many synchronisation operations and writes to the heap. Every time a WRC is cloned it's weight is split in two, with half allocated to the parent and half allocated to the child. When a WRC is dropped it's weight is removed from the total. When the total weight declines to zero then the referenced object is dropped.

Features

  • Thread-safe.
  • Efficient.
  • Lightweight.

Examples

Sharing some immutable data between threads:

use wrc::WRC;
use std::thread;

let five = WRC::new(5);

for _ in 0..10 {
    let five = five.clone();
    thread::spawn(move || {
        println!("{:?}", five);
    });
}

Sharing a mutable AtomicUsize:

use wrc::WRC;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::thread;

let val = WRC::new(AtomicUsize::new(5));

for _ in 0..10 {
    let val = val.clone();

    thread::spawn(move || {
        let v = val.fetch_add(1, Ordering::SeqCst);
        println!("{:?}", v);
    });
}

Status

This create relies on the (currently) unstable shared, unsize and coerce_unsized features, meaning that you need to run an unstable Rust. Other than that it seems legit.

License

Source code is licensed under the terms of the MIT license, the text of which is included in the LICENSE file in this distribution.