AldaronLau / AldaronLau/shared_cell

Yet Another Soundness Issue

Đang mở
#1 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Rust
Star
3
Fork
0
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Current API relies on single threaded `async` task groups to keep there being only one exclusive ref.

This can be broken if someone were to fork the `scoped_tls_hkt` crate to make it async.

Essentially setting the `&mut SharedCell` to a scoped static, `.awaiting` inside the async closure passed to `FOO.set()` and accessing the scoped tls within a the `SharedCell::with()` in order to call `.with()` again reëntrantly.

I think this leaves one API possibility left for using async to guarantee a sound panic-free safely mutably borrowable cell (the goal of this crate).

```rust
async fn task(cx: &mut SharedCell) {
// Closure moves to future, pinned and set atomic ref then yield
cx.with(|cell| cell += 1).await;
}

// Future holding on to task group and
struct With {
task_group: &TaskGroup,
closure: Option<&mut dyn FnOnce(T)>,
// requires a separate type for the future to hold self-reference
...: impl FnOnce(T),
}

struct TaskGroup {
with: AtomicPtr,
}
```

While yielding can consume and run the "with" closure. May be able to simplify too

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.