Skip to content

Commit 5808f66

Browse files
committed
补充 std::jthread 一节,说明 libc++ 存在的问题和解决方案 #12
1 parent 7453f85 commit 5808f66

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

md/02使用线程.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,8 @@ int main(){
919919
}
920920
```
921921
922+
> [运行](https://godbolt.org/z/dz43PT51c)测试。截止目前(`2024/5/29` clang19 未发布) `libc++` 不完全支持 `std::jthread`,建议使用 `clang` 的开发者链接 `libstdc++` 或 `MSVC STL` 进行编译。如果非要使用 `libc++`,可以添加 [`-fexperimental-library`](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fexperimental-library) 编译选项,启用不稳定库功能和实验库功能。这样,我们的这段代码就可以通过编译。
923+
922924
`std::jthread` 提供了三个成员函数进行所谓的**线程停止**:
923925
924926
- `get_stop_source`:返回与 `jthread` 对象关联的 `std::stop_source`,允许从外部请求线程停止。

0 commit comments

Comments
 (0)