Comments (10)
Unlike std's compare_exchange, Atomic::compare_exchange
returns the value that was written. Not sure why it behaves differently from std.
from crossbeam.
This is an occasional problem that will recur after executing "cargo run" multiple times.
from crossbeam.
I believe the error itself is the result of use-after-free.
It is wrong to use the Relaxed ordering everywhere when handling pointers, and the orderings of load in the first spawn and the success ordering of compare_exchange in the second spawn have to be Acquire (load), AcqRel (compare_exchange). The problem may not be only that, though.
from crossbeam.
It seems that this is not the problem. I changed the code to use SeqCst and still get the same error.
from crossbeam.
I tried changing it to this
a.load(Ordering::Acquire, guard)
a.compare_exchange(shared, Owned::new(A(i.to_string())),
Ordering::AcqRel, Ordering::AcqRel, guard)
It results in an error every time it is executed
If 'SeqCst' is used, the probability of errors will be much lower, but there will still be errors
from crossbeam.
loop {
let shared = a.load(Ordering::Relaxed, guard);
match a.compare_exchange(shared, Owned::new(A(i.to_string())),
Ordering::Relaxed, Ordering::Relaxed, guard) {
Ok(rs) => {
unsafe {
guard.defer_destroy(rs);
}
break;
}
Err(_e) => {
// shared = e.current;
}
}
}
Writing like this still leads to errors.If possible, please tell me how to modify it, thank you
from crossbeam.
defer_destroy(shared)
from crossbeam.
defer_destroy(shared)
Am I using the wrong method
from crossbeam.
struct A(String);
fn main() {
let a = Arc::new(Atomic::new(A("0".to_string())));
for _ in 1..100 {
let a = a.clone();
thread::spawn(move || {
let guard = &crossbeam_epoch::pin();
- let mut shared = a.load(Ordering::Relaxed, guard);
+ let mut shared = a.load(Ordering::Acquire, guard);
unsafe {
println!("{}",shared.as_ref().unwrap().0);
}
});
}
for i in 1..100 {
let a = a.clone();
thread::spawn(move || {
let guard = &crossbeam_epoch::pin();
let mut shared = a.load(Ordering::Relaxed, guard);
loop {
match a.compare_exchange(shared, Owned::new(A(i.to_string())),
- Ordering::Relaxed, Ordering::Relaxed, guard) {
+ Ordering::AcqRel, Ordering::Relaxed, guard) {
Ok(rs) => {
unsafe {
- guard.defer_destroy(rs);
+ guard.defer_destroy(shared);
}
break;
}
Err(e) => {
shared = e.current;
}
}
}
});
}
}
from crossbeam.
unsafe { - guard.defer_destroy(rs); + guard.defer_destroy(shared); }
Thank you. This has solved the above problem
from crossbeam.
Related Issues (20)
- performance issues with memory ordering
- Panicked during `epoch::pin()` HOT 9
- Implement fmt::Display for CachePadded where T: Display HOT 1
- Thread-safe, shared-state concurrency with `WaitGroup` HOT 2
- crossbeam-utils fails to compile on esp32* targets starting Rust 1.74 HOT 3
- provide a scoped thread start taht returns result HOT 1
- Potential to modify the ordering for 'load' operations in the garbage module of branch 0.2.10 HOT 4
- Move CachePadded to separate sub-crate? HOT 5
- Fine-tune the ordering for received HOT 2
- Supporting `allocator_api` HOT 1
- `#[cfg(...)]` in the select macro
- crossbeam::skiplist: make iterator sendable to anther threads HOT 1
- select_macro.rs's fairness2 test is flaky with sanitizer
- Channel `select` panics "passed a receiver that wasn't selected" when using different clones of the same receiver HOT 2
- Use SkipMap as a lock free concurrent mutable hash map? HOT 2
- Complexity O() HOT 2
- Add `with_capacity` constructor
- Potential deadlock and resource leak when `Receiver` is dropped in `crossbeam_channel`'s bounded channel HOT 1
- crossbeam-channel has better performance with binded CPU ? HOT 3
- A question regarding Miri error running the “sanitize" example under crossbeam-epoch.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crossbeam.