edef1c / libfringe

a Rust library implementing safe, lightweight context switches, without relying on kernel services
https://edef1c.github.io/libfringe
Apache License 2.0
512 stars 31 forks source link

Don't implement Send at all #67

Closed edef1c closed 7 years ago

edef1c commented 7 years ago

On hosted platforms, libstd allows safely borrowing values from TLS with 'thread lifetime and without a Sync bound. As a result, we can't guarantee that sending a generator across threads won't create dangling references or data races. In freestanding environments, the notion of thread-safety is likely to be defined by the consumer of libfringe, so our Send bounds and implementation are unlikely to be meaningful anyway.

Amanieu commented 7 years ago

More specifically, we can only make a generator Send if everything on the generator stack is Send. Since we have no practical way of enforcing that, we must be conservative and not make generators Send.

whitequark commented 7 years ago

Wait, we don't have a 'thread lifetime: https://github.com/rust-lang/rfcs/pull/1705#issuecomment-260061724.

edef1c commented 7 years ago

@whitequark The actual lifetime of TLS memory is (at most) 'thread, but that's indeed not expressible in the type system.