I am writing a program for a producer-consumer problem.
Producer produces data and pushes data into boost::spsc_queue
and the consumer processes it.
In consumer thread, I am using JNI
to call some java functions from my code written in c++.
I am initializing and creating JVM
in the function itself called by the consumer thread and then the event loop starts in which it pops data from boost::spsc_queue
and process it.
Now, I want to catch SIGINT
signal, so I have written a signal_handler
and register it in my main()
function. But it is not working.
If I comment out all JNI stuff and just start a loop while(1){}
there in the function called by consumer thread, then it is catching SIGINT and working as it is supposed to work.
Is something more which I need to take care for JVM or JNI stuff? Shall I try the same thing after initializing and creating JVM in the main thread? Does it make sense?
答案 0 :(得分:2)
看来,您需要-Xrs
option
-Xrs
减少JVM对操作系统信号的使用。
...
嵌入JVM的应用程序经常需要捕获
SIGINT
或SIGTERM
等信号,这可能会导致对JVM信号处理程序的干扰。-Xrs
选项可用于解决此问题。使用-Xrs
时,JVM不会更改SIGINT
,SIGTERM
,SIGHUP
和SIGQUIT
的信号掩码,以及这些信号的信号处理程序没有安装。指定
-Xrs
有两个后果:
SIGQUIT
线程转储不可用。用户代码负责导致关闭挂钩运行,例如,在终止JVM时调用
System.exit()
。
您可以在传递给JNI_CreateJavaVM(…)
的JavaVMInitArgs
中指定此类选项。
答案 1 :(得分:1)
是的,JVM使用信号处理程序用于自己的目的,这就是你需要特别关心信号链的原因。 Read more >