我非常初來乍到的多線程編程,所以這個問題似乎有點傻,遵循的是我的代碼,我想有2個線程:多線程程序和信號
struct sigaction S1,S2;
struct itimerval T1,T2;
void Function1(){
cout<<"Function1 "<<endl;
}
void Function2(){
cout<<"Function2 "<<endl;
}
void Thread_Function(){
int t=70000;
memset (&s2, 0, sizeof (s2));
s2.sa_handler = &Function2;
sigaction (SIGALRM, &s2, NULL);
sigemptyset(&s2.sa_mask);
s2.sa_flags = 0;
T2.it_value.tv_sec = 0;
T2.it_value.tv_usec =t;
T2.it_interval.tv_sec =0;
T2.it_interval.tv_usec =t;
setitimer (ITIMER_REAL, &T2, NULL);
}
int main(){
int t=50000;
memset (&s1, 0, sizeof (s1));
s1.sa_handler = &Function1;
sigaction (SIGALRM, &s1, NULL);
sigemptyset(&s1.sa_mask);
s1.sa_flags = 0;
T1.it_value.tv_sec = 0;
T1.it_value.tv_usec =t;
T1.it_interval.tv_sec =0;
T1.it_interval.tv_usec =t;
setitimer (ITIMER_REAL, &T1, NULL);
thread t1(Thread_Function);
}
問題是Function1
換句話說,不執行我不能看到Function1
我的輸出
不函數2執行? – Hayt
是的,它正確執行 –