Skip to content

Commit 289489a

Browse files
docs: Update the documentation for the new concurrency strategy interface
1 parent c89b99a commit 289489a

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,29 @@ auto maybe = x + y; // std::expected<primitive<int, policy::error::expected>, po
5151
- `policy::value::{checked, unchecked, saturating}`
5252
- `policy::type::{strict, compatible, transparent}`
5353
- `policy::error::{throwing, expected, terminate}`
54-
- `policy::concurrency::{none, atomic}`
54+
- `policy::concurrency::{none, fenced, fenced_relaxed, fenced_acq_rel, fenced_seq_cst}`
55+
56+
并发策略说明:
57+
58+
- `fenced*` 系列是操作级并发语义,通过策略注入内存序 fence;
59+
- `primitive` 存储仍保持统一、零开销布局,不引入额外存储层抽象;
60+
- `primitive::load/store/compare_exchange` 由并发策略的协议实现提供,若策略未实现该协议会在编译期报错。
61+
62+
示例(并发访问 API):
63+
64+
```cpp
65+
using shared_t = primitive<int, policy::value::checked,
66+
policy::concurrency::fenced_acq_rel,
67+
policy::error::expected>;
68+
69+
shared_t v{1};
70+
v.store(2);
71+
auto expected = 2;
72+
if (v.compare_exchange(expected, 3)) {
73+
auto now = v.load();
74+
(void)now;
75+
}
76+
```
5577

5678
默认策略位于 `policy::defaults`
5779

0 commit comments

Comments
 (0)