-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
141 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "cds" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) 2024 Xu Shaohua <[email protected]>. All rights reserved. | ||
// Use of this source is governed by General Public License that can be found | ||
// in the LICENSE file. | ||
|
||
#![deny( | ||
warnings, | ||
clippy::all, | ||
clippy::cargo, | ||
clippy::nursery, | ||
clippy::pedantic | ||
)] | ||
|
||
//pub mod lock_coupling_linked_list; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2024 Xu Shaohua <[email protected]>. All rights reserved. | ||
// Use of this source is governed by GNU General Public License | ||
// that can be found in the LICENSE file. | ||
|
||
use std::ptr::NonNull; | ||
use std::sync::Mutex; | ||
|
||
pub struct LockCouplingLinkedList<T> { | ||
len: usize, | ||
head: NodePtr<T>, | ||
} | ||
|
||
type NodePtr<T> = Mutex<Option<NonNull<Node<T>>>>; | ||
|
||
pub struct Node<T> { | ||
next: NodePtr<T>, | ||
value: T, | ||
} | ||
|
||
impl<T> LockCouplingLinkedList<T> {} | ||
|
||
impl<T> Node<T> { | ||
#[must_use] | ||
fn new(value: T) -> Self { | ||
Self { | ||
next: Mutex::new(None), | ||
value, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Concurrent Deque |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Concurrent Hash Map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Concurrent List |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Concurrent Queue | ||
|
||
Multi-producer, multi-consumer lock-free FIFO | ||
|
||
## 参考 | ||
|
||
- [ConcurrentQueue](https://github.com/cameron314/concurrentqueue) | ||
- [A Fast General Purpose Lock-Free Queue for C++](https://moodycamel.com/blog/2014/a-fast-general-purpose-lock-free-queue-for-c++) | ||
- [A Fast Lock-Free Queue for C++](https://moodycamel.com/blog/2013/a-fast-lock-free-queue-for-c++) | ||
- [Detailed Design of a Lock-Free Queue](https://moodycamel.com/blog/2014/detailed-design-of-a-lock-free-queue) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Concurrent Radix Tree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Concurrent Ring Buffer | ||
|
||
Single-producer, single-consumer lock-free FIFO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Concurrent SkipList Map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Concurrent SkipList Set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# 并发数据结构 Concurrent Data Structures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# 简介 | ||
|
||
并发数据结构 Concurrent data structures, CDS 有三个关键的主题: | ||
|
||
- 安全 Safety, 满足多线程并发的规范 | ||
- 顺序规则 sequential specification, 像一个队列一样按顺序操作 | ||
- 同步 synchronization | ||
- 可扩展性 Scalability, 随着处理器核心数的增多, 性能更好 | ||
- 理想情况下, 线性递增 | ||
- 实际情况, 超过 16 个线程之后, 会退化成次线性递增 (sublinear scaling) | ||
- 有进度 Progress, 保证操作过程向前推进 | ||
- lock freedom: 至少有一个进度向前推进 | ||
- wait freedom: 所有的进度都向前推进 | ||
|
||
## 安全性 Safety | ||
|
||
使用锁或者其它同步原语 (primitive synchronization) 来保护并发数据结构. | ||
|
||
- 使用全局锁来保护顺序数据结构 | ||
- 使用自定义的同步协议来保护数据结构 | ||
|
||
## 可扩展性 Scalability | ||
|
||
- 减少锁保护的作用域 | ||
- 读写锁 read-write locking | ||
- hand-over-hand locking | ||
- lock coupling | ||
- 避免写数据以便减少无效的缓存 | ||
- 乐观锁 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Lock-coupling Linked List |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Skip Graph | ||
|
||
## 参考 | ||
|
||
- [Skip graph](https://en.wikipedia.org/wiki/Skip_graph) |