pull_number
int64 | hints_text
string | patch
string | test_patch
string | version
string | problem_statement
string | created_at
string | instance_id
string | repo
string | issue_numbers
sequence | base_commit
string | environment_setup_commit
string | FAIL_TO_PASS
sequence | PASS_TO_PASS
sequence | FAIL_TO_FAIL
sequence | PASS_TO_FAIL
sequence |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1,101
|
Thanks for the report!
IIUC, insert reduces the refcount of the old value and then sets the new value, so if insert makes the refcount zero, a get that occurs between the time the refcount is reduced and the new value is set will return None because it sees a deleted value with a refcount of zero.
Do you have any plans to fix it
I consider it a bug that needs to be fixed, but I'm not sure if I will be able to work on a fix anytime soon.
It would be great if you or someone else could work on a fix.
|
diff --git a/crossbeam-skiplist/src/base.rs b/crossbeam-skiplist/src/base.rs
index adee38472..8041718fe 100644
--- a/crossbeam-skiplist/src/base.rs
+++ b/crossbeam-skiplist/src/base.rs
@@ -871,33 +871,17 @@ where
// the lifetime of the guard.
let guard = &*(guard as *const _);
- let mut search;
- loop {
- // First try searching for the key.
- // Note that the `Ord` implementation for `K` may panic during the search.
- search = self.search_position(&key, guard);
-
- let r = match search.found {
- Some(r) => r,
- None => break,
- };
+ // First try searching for the key.
+ // Note that the `Ord` implementation for `K` may panic during the search.
+ let mut search = self.search_position(&key, guard);
+ if let Some(r) = search.found {
let replace = replace(&r.value);
- if replace {
- // If a node with the key was found and we should replace it, mark its tower
- // and then repeat the search.
- if r.mark_tower() {
- self.hot_data.len.fetch_sub(1, Ordering::Relaxed);
- }
- } else {
+ if !replace {
// If a node with the key was found and we're not going to replace it, let's
// try returning it as an entry.
if let Some(e) = RefEntry::try_acquire(self, r) {
return e;
}
-
- // If we couldn't increment the reference count, that means someone has just
- // now removed the node.
- break;
}
}
@@ -937,6 +921,12 @@ where
)
.is_ok()
{
+ // This node has been abandoned
+ if let Some(r) = search.found {
+ if r.mark_tower() {
+ self.hot_data.len.fetch_sub(1, Ordering::Relaxed);
+ }
+ }
break;
}
@@ -956,13 +946,7 @@ where
if let Some(r) = search.found {
let replace = replace(&r.value);
- if replace {
- // If a node with the key was found and we should replace it, mark its
- // tower and then repeat the search.
- if r.mark_tower() {
- self.hot_data.len.fetch_sub(1, Ordering::Relaxed);
- }
- } else {
+ if !replace {
// If a node with the key was found and we're not going to replace it,
// let's try returning it as an entry.
if let Some(e) = RefEntry::try_acquire(self, r) {
|
diff --git a/crossbeam-skiplist/tests/map.rs b/crossbeam-skiplist/tests/map.rs
index 57c819d21..e5145fb06 100644
--- a/crossbeam-skiplist/tests/map.rs
+++ b/crossbeam-skiplist/tests/map.rs
@@ -920,3 +920,24 @@ fn clear() {
assert!(s.is_empty());
assert_eq!(s.len(), 0);
}
+
+// https://github.com/crossbeam-rs/crossbeam/issues/1023
+#[test]
+fn concurrent_insert_get_same_key() {
+ use std::sync::Arc;
+ let map: Arc<SkipMap<u32, ()>> = Arc::new(SkipMap::new());
+ let len = 10_0000;
+ let key = 0;
+ map.insert(0, ());
+
+ let getter = map.clone();
+ let handle = std::thread::spawn(move || {
+ for _ in 0..len {
+ map.insert(0, ());
+ }
+ });
+ for _ in 0..len {
+ assert!(getter.get(&key).is_some());
+ }
+ handle.join().unwrap()
+}
diff --git a/crossbeam-skiplist/tests/set.rs b/crossbeam-skiplist/tests/set.rs
index b6987b8bb..ab769003c 100644
--- a/crossbeam-skiplist/tests/set.rs
+++ b/crossbeam-skiplist/tests/set.rs
@@ -692,3 +692,24 @@ fn clear() {
assert!(s.is_empty());
assert_eq!(s.len(), 0);
}
+
+// https://github.com/crossbeam-rs/crossbeam/issues/1023
+#[test]
+fn concurrent_insert_get_same_key() {
+ use std::sync::Arc;
+ let set: Arc<SkipSet<u32>> = Arc::new(SkipSet::new());
+ let len = 10_0000;
+ let key = 0;
+ set.insert(0);
+
+ let getter = set.clone();
+ let handle = std::thread::spawn(move || {
+ for _ in 0..len {
+ set.insert(0);
+ }
+ });
+ for _ in 0..len {
+ assert!(getter.get(&key).is_some());
+ }
+ handle.join().unwrap()
+}
|
0.8
|
crossbeam-skiplist bug
[dependencies]
crossbeam-skiplist = "0.1.1"
```rs
fn main() {
let map: Arc<SkipMap<u32, u32>> = Arc::new(SkipMap::new());
map.insert(1, 2);
let map1 = map.clone();
std::thread::spawn(move||{
let key = 1;
for _ in 0..10_0000 {
let len = map1.len();
if let Some(entry) = map1.get(&key) {
}else{
panic!("len={},key={}",len,key);
}
std::thread::sleep(Duration::from_millis(1));
}
});
for _ in 0..10_0000 {
map.insert(1, 2);
std::thread::sleep(Duration::from_millis(100));
}
}
```
output:
```
thread '<unnamed>' panicked at 'len=1,key=1', src\main.rs:21:17
stack backtrace:
```
|
2024-04-12T12:16:27Z
|
crossbeam-rs__crossbeam-1101
|
crossbeam-rs/crossbeam
|
[
"1023"
] |
9e8596105bc9a6b343918b6ad1c9656dc24dc4f9
|
9e8596105bc9a6b343918b6ad1c9656dc24dc4f9
|
[
"concurrent_insert_get_same_key"
] |
[
"clear",
"compare_and_insert",
"compare_insert_with_absent_key",
"entry_remove",
"entry",
"entry_reposition",
"get",
"get_or_insert_with",
"get_or_insert",
"front_and_back",
"insert_and_remove",
"into_iter",
"is_empty",
"get_next_prev",
"insert",
"iter_range2",
"iter",
"ordered_iter",
"len",
"range_next_memory_leak",
"lower_bound",
"remove",
"next_memory_leak",
"next_back_memory_leak",
"ordered_range",
"smoke",
"iter_range",
"get_or_insert_with_panic",
"upper_bound",
"concurrent_compare_and_insert",
"concurrent_insert",
"concurrent_remove",
"get_or_insert_with_parallel_run"
] |
[] |
[] |
README.md exists but content is empty.
- Downloads last month
- 1