You cannot. Unity thread is not like normal programs, in the sense that it is frame-based. You can ask Unity main thread to run methods, by setting a bool that is being checked at every frame or by setting an <Action>
Or <Task>
Queue, like it is explained in the link suggested by remy_rm in the comment above.
But these hacks don’t run methods on unity main thread, they just gracefully ask Unity main thread itself to run it. The difference, while subtle in normal cases, becomes vital with your problem. You want to call a method on the main thread to kill it when it’s stuck on an endless loop, but isn’t that case, Unity’s main thread will never reach the point in Update()
where it’s supposed to kill itself. You basically send a letter to someone who is never coming back home, and he will never read it if he is stuck somewhere and cannot reach home.
Best way, that springs in my mind, in those cases, is to attach a debugger and stop the thread from it.