2012-10-05 1 views
0

그래서이 코드는 최근까지 Lubuntu 12.04 시스템으로 옮길 때까지 잘 작동했습니다. 이 유일한해야하기 때문에itimerspec의 모든 구성원이 설정되어 있어도 timer_settime이 실패합니다.

1067  if(-1 ==timer_settime(tid,0,&ts,NULL)) 
(gdb) print ts 
$1 = {it_interval = {tv_sec = 0, tv_nsec = 200000000}, it_value = {tv_sec = 0, 
tv_nsec = 0}} 

: timer_settime에 대한 호출은 내가 TS의 모든 필드가 호출되는 시점에 0 999999999 내에 있다는 것을 확인했습니다 EINVAL을 반환하고, GDB 아래를 실행 그것은 그것이 EINVAL을 돌려 줄 수 있습니다. 나는 매우 당혹 스럽습니다. 어쩌면 여기서 내가 분실 한 것이 분명해 보입니다.

struct sigevent sev; 
struct itimerspec ts; 
timer_t *tid; 
//actually point the pointer at something. 
tid = calloc(1,sizeof(timer_t)); 
//make sure there's no garbage in the structures. 
memset(&sev,0,sizeof(struct sigevent)); 
memset(&ts,0, sizeof(struct itimerspec)); 
//notify via thread 
sev.sigev_notify = SIGEV_THREAD; 
sev.sigev_notify_function = SwitchThreadHandler; 
sev.sigev_notify_attributes = NULL; 
sev.sigev_value.sival_ptr = tid; 
ts.it_value.tv_sec =0; 
ts.it_value.tv_nsec = 0; 
ts.it_interval.tv_sec = 0; 
ts.it_interval.tv_nsec = 200000000; 
if(-1 == timer_create(CLOCK_REALTIME,&sev,tid)) 
{ 
    retval = EX_SOFTWARE; 
    fprintf(stderr,"Failed to create timer."); 
    free(tid); 
    return retval; 
} 

if(-1 ==timer_settime(tid,0,&ts,NULL)) 
{ 
    int errsv = errno; 
    fprintf(stderr,"timer_settime FAILED!!!\n"); 
    if(errsv == EINVAL) 
    { 
     fprintf(stderr,"INVALID VALUE!\n"); 
    } 
    else 
    { 
     fprintf(stderr,"UNKOWN ERROR: %d\n",errsv); 
    } 
    return EX_SOFTWARE; 
} 

답변

1

timer_settime는 첫번째 인수하지 timer_create 같은 timer_t * 같은 timer_t 복용으로 설명된다. timerid이 유효하지 않은 경우 EINVAL으로 실패합니다.

따라서 첫 번째 인수로 *tid을 전달해야합니다.

컴파일러에서 경고 메시지를 표시해야합니다.

+0

이상하게도 gcc -Wall은 이것에 대해 엿 ​​듣지 않았으며 우리가 시도한 네 가지 환경 중 세 가지에서 완벽하게 작동했습니다. 기묘한. 글쎄, 이제는 더 이상 실패하지 않지만 타이머는 결코 작동하지 않으므로 내가 묻는 질문에 답했습니다. –