basic.%alarm

C Function/BASIC Program, Releases: AP/Unix

Sends SIGALRM to calling process after given delay.

Syntax

variable=%alarm(number)

Description

instructs the alarm clock of the calling process to send the signal 'SIGALRM' to the calling process after the number of seconds specified in 'number'.

The default alarm handler is null (i.e.: it just interrupts the process). If 'number' is 0, any previously made alarm request is canceled. If a user-written built-in function changes the alarm signal handler, it remains in effect, even if the Pick/BASIC program terminates, until the process is disconnected from the virtual machine.

The alarm signal handler can be assigned to any Pick command using the (TCL) 'trap' command.

To differentiate between an alarm and another interrupt, the FlashBASIC or Pick/BASIC program may have to check the time. See the example below.

Example

* Set a timer
alarmend=time()+3
%alarm( 3 )
* Read from device
n=%read(fd, buffer, BUFSIZE)
if n<0 and system(0)=EINTR then
* Read was interrupted
if time() >= alarmend then
* Was the timer
stop 'time out'
end else
* Not the timer. Disarm it
%alarm(0)
end
end else
* Read completed. Cancel timer
%alarm( 0 )
end

See Also

Command Name Type Description
basic.cfunc Definition can be called from a Pick/BASIC program or subroutine in AP/DOS and AP/Unix implementations using a syntax similar to that of normal C.
tcl.trap Verb: Access Maintains %msignals% item in dm account.
basic.cfunction Definition Declare a list of C functions.
tcl.useralarm Verb: Access Alarm handler.

User Comments

What do you think?

Share your experience or ask a question by using the form below.

Login to leave your comments.