2013-09-25 70 views
2

我有一個多線程程序。主線程使用一個getchar來關閉所有其他線程和它自己。我有一個計時器功能在一個子線程中使用。該線程使用SIG34作爲定時器到期。getchar和SIG34,實時事件34

在某些時候,我收到如下的SIG34這影響了我的主線程中的getchar,而我的程序只是中止。請幫助我理解相同。

Program received signal SIG34, Real-time event 34. 
0x00007ffff6ea38cd in read() from /lib/x86_64-linux-gnu/libc.so.6 

(gdb) bt 
#0 0x00007ffff6ea38cd in read() from /lib/x86_64-linux-gnu/libc.so.6 
#1 0x00007ffff6e37ff8 in _IO_file_underflow() from /lib/x86_64-linux-gnu/libc.so.6 
#2 0x00007ffff6e3903e in _IO_default_uflow() from /lib/x86_64-linux-gnu/libc.so.6 
#3 0x00007ffff6e2fb28 in getchar() from /lib/x86_64-linux-gnu/libc.so.6 
#4 0x0000000000401eef in main (argc=1, argv=0x7fffffffe178) at ../../src/SimMain.c:186 

注:

在子線程,我已經指派SIGRTMIN(轉換爲SIG34我的系統上),定時器信號,並有處理程序也。這個處理程序設置一個全局變量來讓我更改課程後定時器到期。但不確定爲什麼getchar有問題。

定時器初始化和使用:

/* Timer macros */ 
    #define CLOCKID CLOCK_REALTIME 
    #define SIGRT_OFFSET 4 // was 0 before, hence, SIG34, now it is SIG38 

    #define SIG (SIGRTMIN + SIGRT_OFFSET) 

    void cc_timer_init() 
{ 
    // Install the timer handler... 

    struct sigevent sev; 
    long long freq_nanosecs; 
    struct sigaction disc_action; 

    /* Establish timer_handler for timer signal */ 


    memset (&disc_action, 0, sizeof (disc_action)); 
    disc_action.sa_flags = SA_SIGINFO; //0 before 
    disc_action.sa_sigaction = disc_timer_handler; 
    sigaction(SIG, &disc_action, NULL); 
    myState = INIT_STATE; 


    /* Create the timer */ 

    sev.sigev_notify = SIGEV_SIGNAL; 
    sev.sigev_signo = SIG; 
    sev.sigev_value.sival_ptr = &timerid; 
    timer_create(CLOCKID, &sev, &timerid); 


    /* Set itimerspec to start the timer */ 

    freq_nanosecs = TMR_TV_NSEC; 
    v_itimerspec.it_value.tv_sec = TMR_TV_SEC; 
    v_itimerspec.it_value.tv_nsec = freq_nanosecs % 1000000000; 
    v_itimerspec.it_interval.tv_sec = 0; 
    v_itimerspec.it_interval.tv_nsec = 0; 

} 

static void disc_timer_handler(int sig, siginfo_t *si, void *uc) 
{ 
    /* Global variable that I set */ 
    State = MID_1_STATE; 
} 

/* In another part...*/ 
. 
. 
. 
case INIT_STATE : 
    { 
     v_itimerspec.it_value.tv_sec = TMR_TV_SEC; 
     timer_settime(timerid, 0, &v_itimerspec, NULL); 
     ret_val = SUCCESS; 
    } 
    break; 
    . 
    . 
    . 
+1

相關(但未回覆):[程序終止接收 - 信號SIG34,實時事件34](http://stackoverflow.com/q/6735791/464709)。 –

+0

你可以顯示設置信號處理程序和定時器的代碼嗎? – nos

+0

@nos計時器創建和信號處理程序顯示 – Aadishri

回答

2

從Ubuntu並行線程信息表(LinuxThreads中)):

 In addition to the main (initial) thread, and the threads that the 
     program creates using pthread_create(3), the implementation creates 
     a "manager" thread. This thread handles thread creation and 
     termination. (Problems can result if this thread is inadvertently 
     killed.) 

    - Signals are used internally by the implementation. On Linux 2.2 and 
     later, the first three real-time signals are used. 

其他實現方式使用前兩個RT信號。將SIGRTMIN設置在線程管理使用的這兩個/三個信號之上。看看你的pthreads(7)手冊頁對SIGRTMIN的看法。並據此調整。

+3

您引用的信息與LinuxThreads相關,而不是NTPL。 LinuxThreads現在還沒有被使用好幾年。 – nos

+3

你是完全正確的。但是,這似乎是問題,而OP沒有聲明內核版本。這是「虛假」RT信號的唯一解釋,除非他的代碼生成了它。感謝您的更正。 +1 –