简体   繁体   English

在主程序中按CTRL-C时,线程变量/句柄会发生什么?

[英]What happens to threads variables / handles when CTRL-C in main program is hit?

I have a C application running on AIX 6.1 using Websphere MQ 6. 我有一个使用Websphere MQ 6在AIX 6.1上运行的C应用程序。

The high level of the application is: 该应用程序的高级级别是:

  • Main C application spawns a seperate THREAD that does the LOOP to get message off the queue. 主C应用程序产生一个单独的THREAD,该THREAD进行LOOP操作以使消息脱离队列。
  • When CTRL-C is hit I have a shutdown hook (via signals) that elegantly sets a "thread running variable" to FALSE and the thread ends. 当按下CTRL-C时,我有一个关闭钩子(通过信号),可以优雅地将“线程运行变量”设置为FALSE,并且线程结束。

The problem is whenever I hit CTRL-C I get the following reason code back: 问题是,每当我按CTRL-C组合键时,我都会得到以下原因码:

2009 - MQRC_CONNECTION_BROKEN 2009年-MQRC_CONNECTION_BROKEN

So even though the MQGET on Websphere MQ is currently running the "connection handle" seems to "die" when I hit CTRL-C 因此,即使在Websphere MQ上的MQGET当前正在运行时,当我按CTRL-C时“连接句柄”似乎也会“消失”

Do I need to declare the connection handle in the thread as volatile or static or something else? 我是否需要在线程中将连接句柄声明为volatile或static或其他?

I assumed my thread shutdown was all 100%....and this connection broken issue is causing horrible logs to be generated on MQSeries... 我以为我的线程关闭全部是100%....并且此连接断开问题导致在MQSeries上生成可怕的日志...

I have posted a similar question to mqseries.net but was just wondering if I am missing some fundamental concept when CTRL-C is hit and my shutdown hook is triggered.... 我已经向mqseries.net发布了类似的问题,但是只是想知道在按CTRL-C并触发我的关闭挂钩时是否缺少一些基本概念。

Any help will be greatly appreciated 任何帮助将不胜感激

Lynton 林顿

With the POSIX thread model consider this: 对于POSIX线程模型,请考虑以下事项:

For any thread that calls pthread_sigmask() and blocks SIGINT, that thread will not receive the CTRC/C. 对于任何调用pthread_sigmask()并阻止SIGINT的线程,该线程将不会接收CTRC / C。 Any of threads including the main thread, that have not blocked the signal will receive it. 包括主线程在内的任何未阻塞信号的线程都将接收该信号。 Handling the signal is different between the parent thread and the threads or LWP's you create. 父线程与您创建的线程或LWP之间的信号处理方式有所不同。

So in the main program, you call sigprocmask() to set up handling SIGINT. 因此,在主程序中,您调用sigprocmask()来设置处理SIGINT。 As you described. 如您所描述。 All of the other threads, on their own, have to block SIGINT, by calling pthread_sigmask(). 所有其他线程都必须通过调用pthread_sigmask()来阻止SIGINT。

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

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