Git Product home page Git Product logo

sendable's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sendable's Issues

Unsoundeness in SendRc

Hi! I believe I have spotted some unsoundness in the SendRc implementation, or more specifically this line of PostSend.

This is the reproducer I came up with, it (usually) doesn't actually behave unsoundly but it does show that there is a reference to the same RefCell on 2 different threads.

use std::{
    cell::RefCell,
    sync::{Arc, Barrier},
};

use sendable::SendRc;

fn main() {
    let mut a = SendRc::new(RefCell::new(1));
    let mut b = SendRc::clone(&a);

    let mut pre_send = SendRc::pre_send();
    pre_send.disable(&mut a);
    pre_send.disable(&mut b);
    let mut post_send = pre_send.ready();

    post_send.enable(&mut a);
    let a_inner = &*a;
    let a_barrier = Arc::new(Barrier::new(2));
    let b_barrier = Arc::clone(&a_barrier);
    std::thread::spawn(move || {
        post_send.enable(&mut b);
        drop(post_send);
        let b_inner = &*b;
        b_barrier.wait();
        println!("{}", b_inner.borrow_mut())
    });
    a_barrier.wait();
    println!("{}", a_inner.borrow_mut());
}

The idea is to exploit the line I linked above by re-enabling one copy of the SendRc on the original thread, before sending the other copy to another thread.

More generally, I think the idea behind the library is sound, and I didn't spot any other unsoundness but I'm not very confident in that.

Consistent drop behaviour

Am I correct to say that it's difficult to prevent this from panicking when the SendRC is being dropped as the drop could be initiated from any thread ?!?

I'm struggling to find a good pattern to ensure that the drop thread has ownership of the SendRC when drop is called.

Do you have any thoughts on this ?

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.