3 ms·
>No way to detect at compile-time whether we are in the main thread Which languages do that? Other than requiring all functions to require a "mainthread" refer
by MichaelGG 11y ago
>No way to detect at compile-time whether we are in the main thread
Which languages do that? Other than requiring all functions to require a "mainthread" reference (perhaps a zero-sized type that lacks the traits to be sent cross-thread) are there ways to achieve this in general?
- acconsta 11y agoAnd... how would that be possible at compile time?
- MichaelGG 11y agoIt's possible at compile time because you won't have the "MainThread" object available unless it's passed in to your other functions. And since you'll deny the traits for sending the object from the main thread to other threads, your methods can never be called. And if you want it to be optional, like "if mainthread", then just accept an Option of MainThread. In fact I see exactly this is proposed in the comments on the article: https://users.rust-lang.org/t/my-gamedever-wishlist-for-rust/2859/7 https://users.rust-lang.org/t/my-gamedever-wishlist-for-rust...
- acconsta 11y agoOh OK, that's cool. I don't think many languages could enforce that.