AI-powered
podcast player
Listen to all your favourite podcasts with AI-powered features
What Are Scoped Threads?
Scoped threads are something that used to exist in rust and then got removed in what's known as the leak apocalypse, which I think Ben has some context on. So scoped threads are essentially let's contrast them with regular threads. When you use the regular standard thread spawn function, you provide a closure and that closure has to be static. What that means is you're only allowed to give it references that live for the entirety of the program or give it ownership of anything that you move into the closure you pass to spawn. The reason why the API has to be a little bit weird like this is to actually guarantee that we can't pull shenanigans inside of the closures to make those references leak