mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-24 00:00:11 +02:00
rt: Scoped should not be Sync (#5765)
If the `Scoped` type is `Sync`, then you can call `set` from two threads in parallel. Since it accesses `inner` without synchronization, this is a data race. This is a soundness issue for the `Scoped` type, but since this is an internal API and we don't use it incorrectly anywhere, no harm is done.
This commit is contained in:
@@ -6,8 +6,6 @@ pub(super) struct Scoped<T> {
|
||||
pub(super) inner: Cell<*const T>,
|
||||
}
|
||||
|
||||
unsafe impl<T> Sync for Scoped<T> {}
|
||||
|
||||
impl<T> Scoped<T> {
|
||||
pub(super) const fn new() -> Scoped<T> {
|
||||
Scoped {
|
||||
@@ -52,7 +50,7 @@ impl<T> Scoped<T> {
|
||||
if val.is_null() {
|
||||
f(None)
|
||||
} else {
|
||||
unsafe { f(Some(&*(val as *const T))) }
|
||||
unsafe { f(Some(&*val)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user