Giter VIP home page Giter VIP logo

cura's Introduction

A sort of an Arc-RwLock combination..

That aims to be simple and straightforward to use when sharing data between threads.

An attempt at creating an Arc-RwLock combination that is straightforward to use and no hassle , instead of worrying about being fast and lean.

  • cloning referefences works like Arc
  • made for sharing objects between threads without worry
  • locking things works like RwLock with write() or read()
  • it spins a few times and then queues if a lock is not obtained
  • miri seems to be happy , so i trust it doesnt leak too much memory etc.
  • requires that everything you stick into it is Send+Sync
  • no need to constantly .unwrap() things instead it will just block forever or blow up

Example

use cura::Cura;
trait Foo:Send+Sync
{
    fn get(&self)->i32;
    fn set(&mut self,i:i32);
}
#[derive(Debug)]
struct FF{i:i32,};
struct BB{i:i32};

impl Foo for FF{
    fn get(&self)->i32{return self.i;}
    fn set(&mut self,i:i32){self.i=i;}
}

impl Foo for BB{
    fn get(&self)->i32{return self.i;}
    fn set(&mut self,i:i32){self.i=i;}
}

let t=FF{i:1};

// you can do straight "from_box" but currently its impossible to
// "alter" unsized types
let foo2:Cura<dyn Foo>=Cura::from_box(Box::new(FF{i:2}));
let foo:Cura<Box<dyn Foo>>=Cura::new(Box::new(t));
let a=foo.clone();
let b=foo.clone();

{
    assert_eq!(a.read().get(),1);
    {
        a.alter(|s|{
            s.set(2);
            Some(())
        });
    }
    {
        a.alter(|s|{ //this only works for Sized types
            *s=Box::new(BB{i:2});
            Some(())
        });
    }
    let lock=a.read();
    let v=lock;
    assert_eq!(v.get(),2)
}//lock dropped here
{
    (*b.write()).set(3); //lock dropped here i think 
}

assert_eq!((*a.read()).get(),3);

cura's People

Contributors

itmo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.