task_defersig
Previous Topic  Next Topic 

Synopsis:

        task_defersig(flag)

Arguments:

     flag = Either 1 or “(“ to defer jump to onsignal, else 0 or “)” to clear previous defer request.

Description:     This call is used to prevent a jump to onsignal from occurring until a particular block of code has finished executing.     Each time task_defersig() is called with flag set to 1 or “(“ a counter is increased.     Each time task_defersig() is called with flag set to 0 or “)” a counter is decreased (but not below 0).      If a signal is received whilst the counter is higher than zero then the jump to onsignal will not occur until the counter reaches zero again (through corresponding calls to task_defersig(0) or a call to task_clrdefer()).


Calls to task_defersig(1) can be nested, but the programmer must make sure there is a corresponding task_defersig(0) to match (or a single call to task_clrdefer()) otherwise the task can never respond to signal events.       This is a very common bug and can cause channels to get stuck if no other method is employed to detect a hangup event (such a noticing that the caller has stopped responding to menus).


The programmer should use task_defersig() during database updates or file writes or anywhere else where a hangup signal need to be temporarily ignored..


For example:


// Prevent jumps to onsignal while we write to a file..

task_defersig(1);


// Carry out some tasks that should not be interrupted…

write_to_log(“This cannot be interrupted by a hangup_signal”);


// Now allow jumps to onsignal again…

task_defersig(0).


Note that instead of passing 1 and 0 to task_defersig() you can pass “(“ and “)” instead which reflects the nested nature of the calls to this function, but this is up to programmer preference E.g.


// Prevent jumps to onsignal while we write to a file..

task_defersig(“(“);


// Carry out some tasks that should not be interrupted…

write_to_log(“This cannot be interrupted by a hangup_signal”);


// Now allow jumps to onsignal again…

task_defersig(“)”).

   

This maybe more intuitive for some programmers since it reminds the programmer that all “(“ must be matched by a corresponding “)”.



Again watch out for bugs like this:


func f()

   task_defersig(“(“);


   x=do_something_important();

   // check for error

   if(x < 0)

       // This looks like a bug since a corresponding

       // task_defersig is not being called before returning

       // from the function.

       return x

   end


   // This is OK but where is the one in the if statement above!!??

   task_defersig(“)“);

endfunc


Return Value:


Returns an empty string “”.