frogtd / rose_bloom Goto Github PK
View Code? Open in Web Editor NEWA concurrent growing element size linked list with stable pointers.
License: MIT License
A concurrent growing element size linked list with stable pointers.
License: MIT License
(Fails under miri)
#[test]
fn first_works() {
extern crate std;
use std::thread;
let rose = Rose::new();
rose.push(1);
thread::scope(|s| {
s.spawn(|| {
for _ in 0..10 {
rose.push(1);
}
});
s.spawn(|| {
// This should work because we pushed 1 item earlier
// so no matter how many items we have, there's always *a* first
for _ in 0..10 {
rose.first().unwrap();
}
});
});
}
Looks like an atomic memory ordering issue, where the total length and the sum total of the length of each item disagree.
It would be worth adding a promise that "after getting some value n
from rose.len()
, it is promised that rose.get(x)
for any value x
inside 0..n
will return Some". (And add a test for that)
Since that's what the current first
code relies on anyways.
With the following test:
#[test]
fn concurrent() {
extern crate std;
use alloc::boxed::Box;
use std::thread;
let rose = Rose::new();
rose.push(Box::new(1));
thread::scope(|s| {
let t1 = s.spawn(|| {
rose.push(Box::new(1));
});
let t2 = s.spawn(|| {
rose.push(Box::new(1));
});
});
}
Miri fails with the following error
running 2 tests
test tests::concurrent ... error: Undefined Behavior: Data race detected between Read on thread `<unnamed>` and Write on thread `<unnamed>` at alloc78244
--> src/lib.rs:135:37
|
135 | let capacity = unsafe { (*last).capacity };
| ^^^^^^^^^^^^^^^^ Data race detected between Read on thread `<unnamed>` and Write on thread `<unnamed>` at alloc78244
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: inside `Rose::<alloc::boxed::Box<i32>>::push` at src/lib.rs:135:37
note: inside closure at src/lib.rs:266:17
--> src/lib.rs:266:17
|
266 | rose.push(Box::new(1));
| ^^^^^^^^^^^^^^^^^^^^^^
Also, this happens even if weak memory emulation is disabled, so it's not weak memory. Orderings presumably need to be stronger, somewhere.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.