Hi, <br><br>I tried to implement linux timer with timer_create and signals, but an exception always fired (External:SIGUSR1).<br>It was a lcl program, but I narrowed it to a console one.<br>Here is the lines without extra codes of releasing (the error appears before), <br>
What can be wrong with the code below?<br><br>Thanks in advance,<br><br>Max<br><br>==================================<br><br>program ConsTest;<br><br>uses ... libc, baseunix;<br><br>procedure PosixTimerHandler(signal: longint; info: psiginfo; context: psigcontext);cdecl;<br>
begin<br> Now; // <- Never stops here. <br>end;<br><br><br>procedure TMyApplication.DoRun;<br>var<br> ...<br> fnewact: SigActionRec;<br> fits: itimerspec;<br> sev: sigevent;<br> timerid: timer_t;<br>begin<br>...<br>
{ add your program here }<br><br> FillChar(fnewact, sizeof(SigActionRec),0);<br> fnewact.sa_handler := @PosixTimerHandler;<br> fnewact.sa_flags:=SA_SIGINFO;<br> if fpsigaction(SIGUSR1,@fnewact, Nil) <> 0 then<br>
raise Exception.Create('sigaction failed');<br><br> sev.sigev_notify := SIGEV_SIGNAL;<br> sev.sigev_signo := SIGUSR1;<br> timer_create(CLOCK_REALTIME, @sev, @timerid);<br><br> fits.it_value.tv_sec := 1;<br>
fits.it_value.tv_nsec := 0;<br> fits.it_interval.tv_sec := 1;<br> fits.it_interval.tv_nsec := 0;<br><br> timer_settime(timerid, 0, @fits, Nil);<br><br> ReadLn(); // <- raise External:SIGUSR1. With debug fpc rtl, the line stops at "call psysinfo" inside FpSysCall<br>
<br>