Why thread termination is illegal

Hello, why it would be UB to terminate the thread spawn spawned by thread::spawn (a 'static closure)?

As I see it, it would be equivalent to OS never scheduling the thread, that should be fine.

Why do you think this is UB? I can't remember this claim anywhere.

I expect your describing something that is platform specific. There is possibility it could mess with thread local destruction and join handles, which the compiler does not give any guarantees over. (work today broken tomorrow.)

The difference between the two is that terminating a thread frees its stack, while never scheduling it is more akin to leaking.

Unsafe code generally assumes that the stack won't be freed without first running local variable destructors, hence why the first is UB.

5 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.