[fpc-pascal] timer_create on linux

Max Vlasov max.vlasov at gmail.com
Wed Aug 10 11:18:16 CEST 2011


Hi,

I tried to implement linux timer with timer_create and signals, but an
exception always fired (External:SIGUSR1).
It was a lcl program, but I narrowed it to a console one.
Here is the lines without extra codes of releasing (the error appears
before),
What can be wrong with the code below?

Thanks in advance,

Max

==================================

program ConsTest;

uses ... libc, baseunix;

procedure PosixTimerHandler(signal: longint; info: psiginfo; context:
psigcontext);cdecl;
begin
  Now; // <- Never stops here.
end;


procedure TMyApplication.DoRun;
var
  ...
  fnewact: SigActionRec;
  fits: itimerspec;
  sev: sigevent;
  timerid: timer_t;
begin
...
  { add your program here }

  FillChar(fnewact, sizeof(SigActionRec),0);
  fnewact.sa_handler := @PosixTimerHandler;
  fnewact.sa_flags:=SA_SIGINFO;
  if fpsigaction(SIGUSR1, at fnewact, Nil) <> 0 then
    raise Exception.Create('sigaction failed');

  sev.sigev_notify := SIGEV_SIGNAL;
  sev.sigev_signo := SIGUSR1;
  timer_create(CLOCK_REALTIME, @sev, @timerid);

  fits.it_value.tv_sec := 1;
  fits.it_value.tv_nsec := 0;
  fits.it_interval.tv_sec := 1;
  fits.it_interval.tv_nsec := 0;

  timer_settime(timerid, 0, @fits, Nil);

  ReadLn(); // <- raise External:SIGUSR1. With debug fpc rtl, the line stops
at "call  psysinfo" inside FpSysCall
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20110810/81ebc53c/attachment.html>


More information about the fpc-pascal mailing list