Is there a difference between the first thread and other threads created during runtime. Because I have a program where to abort longjmp is used and a thread should be able to terminate the program (exit or abort don't work in my case). Could I safely use pthread_kill_other_threads_np and then longjmp?
Asked
Active
Viewed 185 times
0
-
`longjmp`? In 2021? Whatever is going on here? This sounds like an XY Problem. What's the actual issue you're trying to solve? – tadman Feb 15 '21 at 23:03
-
Nothing wrong with `longjmp`, but indeed it sounds like an XY problem – R.. GitHub STOP HELPING ICE Feb 16 '21 at 00:42
-
1`exit` will exit all threads, terminating the program. Why won't it work in your case? Do some of the threads need cleanup before they can exit? – Chris Dodd Feb 16 '21 at 00:46
-
The 'main thread' is created by the OS process loader, rather than your app code. Apart from that, no, they are all just threads:) – Martin James Feb 16 '21 at 05:56
1 Answers
3
I'm not sure what platform you're talking about, but pthread_kill_other_threads_np
is not a standard function and not a remotely reasonable operation anymore than free_all_malloced_memory
would be. Process termination inherently involves the termination of all threads atomically with respect to each other (they don't see each other terminate).
As for longjmp
, while there is nothing wrong with longjmp
, you cannot use it to jump to a context in a different thread.
It sounds like you have an XY problem here; you've asked about whether you can use (or how to use) particular tools that are not the right tool for whatever it is you want, without actually explaining what your constraints are.

R.. GitHub STOP HELPING ICE
- 208,859
- 35
- 376
- 711