简体   繁体   English

C 主线程与其他线程的区别

[英]C difference between main thread and other threads

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).因为我有一个使用 longjmp 中止的程序,并且一个线程应该能够终止该程序(在我的情况下退出或中止不起作用)。 Could I safely use pthread_kill_other_threads_np and then longjmp?我可以安全地使用 pthread_kill_other_threads_np 然后 longjmp 吗?

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.我不确定您在说什么平台,但是pthread_kill_other_threads_np不是标准的 function 并且不再是比free_all_malloced_memory更合理的操作。 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.至于longjmp ,虽然longjmp没有任何问题,但您不能使用它来跳转到不同线程中的上下文。

It sounds like you have an XY problem here;听起来你这里有一个 XY 问题; 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.您已经询问是否可以使用(或如何使用)特定工具,这些工具对于您想要的任何东西都不是正确的工具,而没有实际解释您的约束是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM