dekker 0.1.0

Implementation of Dekker's algorithm for mutual exclusion.
Documentation
  • Coverage
  • 71.43%
    5 out of 7 items documented0 out of 7 items with examples
  • Size
  • Source code size: 6.56 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 609.63 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • fabianboesiger/dekker
    0 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • fabianboesiger

Dekker

This crate provides an implementation of Dekker's algorithm. Dekker's algorithm is the first known correct solution to the mutual exclusion problem in concurrent programming.

Example

use dekker::Dekker;
use std::thread;

fn main() {
    // Create two process handles.
    let (mut p1, mut p2) = Dekker::new(0);

    // Create a new thread and move one handle.
    let other = thread::spawn(move || {
        // Increment by one five times.
        for _ in 0..5 {
            println!("Incrementing in secondary thread.");
            *p2.lock() += 1;
        }
    });

    // Increment by one another five times.
    for _ in 0..5 {
        println!("Incrementing in main thread.");
        *p1.lock() += 1;
    }

    // Join the threads.
    other.join().unwrap();

    println!("The counter is now at {}.", *p1.lock());
}

A possible output looks like this:

Incrementing in main thread.
Incrementing in secondary thread.
Incrementing in secondary thread.
Incrementing in main thread.
Incrementing in secondary thread.
Incrementing in main thread.
Incrementing in main thread.
Incrementing in secondary thread.
Incrementing in secondary thread.
Incrementing in main thread.
The counter is now at 10.

In the end, the counter will always be at 10.