mousey
mousey

Reputation: 11901

Question regarding multiple threads and segfaults

What happens when two threads of the same process running on different logical cpu hit a seg fault?

Upvotes: 3

Views: 2781

Answers (5)

nmichaels
nmichaels

Reputation: 50951

The segfault handler is called for the process. If you don't do anything special, the OS will kill the process and reclaim its resources.

Upvotes: 0

aeh
aeh

Reputation: 775

Signals generated due to illegal execution are handled synchronously by the kernel. So even if both the threads generate seg fault at the same time, only one gets thru'.

Upvotes: 1

R.. GitHub STOP HELPING ICE
R.. GitHub STOP HELPING ICE

Reputation: 215257

Default action is for the process to exit. If you handle the segfault, I suppose you could try to arrange for just the thread where it happened to terminate. However, since the only things which cause a segfault to occur naturally (as opposed to raise or kill) stem from undefined behavior, the program is in an indeterminate state and you can't rely on being able to recover anything.

Upvotes: 5

doron
doron

Reputation: 28892

Normal handling of a Segmentation Fault involves the termination of the process. That means that both of them are terminated.

Upvotes: 5

Matthew Flaschen
Matthew Flaschen

Reputation: 284816

I think the default action on all major OSes is to terminate the process. However, you could conceivably install (e.g using signal) an alternate handler that only terminated the thread. Of course, once you have a segmentation fault, behavior typically becomes undefined, and attempting to continue is risky.

Upvotes: 2

Related Questions