No, a thread can stop (and potentially never resume) also because of mutual exclusion locks. Since threads are part of the same process they can access the same memory addresses; since they run in parallel, setting a global variable in multiple threads means the final value is unpredictable or even cause a crash or memory leak. Thus, threads synchronize themselves by waiting (i.e. stopping execution) until the thread operating on the shared state is done.moonbob69 wrote:The only way a thread stops is if it decides it is done, decides to wait for something, or the CPU interrupts it, literally with the CPU hardware.
It is up to the programmer to properly set up this mechanism, the OS only provides the tools and the processor knows nothing about that.
On Unix-like systems, some errors similar to that have a signal, so programs can potentially handle them.moonbob69 wrote:Do threads get to set their own error entry points to respond to specific anticipated errors like divide-by-zero?
Handlers are normal functions like everything else.moonbob64 wrote:If a process has a handler, that sounds like interrupt-code itself; such code is only entitled to copy the information into its own memory space and return, and then work on that signal in its own time-slice later. How do signals work? Does a process have more than one entry point. or is the only entry point supposed to check for signals to see it it is being run for the first time or in response to a signal?
The difference is that they are used as values of a special vector that the OS creates when the program is executed.
When the OS sends a signal to the process what it means is that the process calls this function instead of performing the operation it would perform otherwise.
Signals are handled completely at the OS level, they have nothing to do with the processor or interrupts.
Also, if the signal handler is fast enough (as it should be for unrelated reasons), the process can handle a signal without having to wait for the next time slice.
Doesn't that box have a "stop execution" (or however it's called) button?moonbob64 wrote: I had asked previously if anyone knew how the "unresponsive script" box was triggered, and how much trouble it would be to have a stop button that knew where scripts were and stop them.
Also it's triggered after a script executes for a certain amount of time without stopping.