Linux- reentrant function (a fastMacedonia Day10)

table of Contents

First, the signal blocking signal pending

Two, pause (2) using

Third, the signal transmitted during the processing

Fourth, the reentrant function

Fifth, write code to implement the signal processing functions of inheritance

Six, setitimer achieve timer


 

 

Fourth, the reentrant function

   Function uses the variable space allocated in the stack frame of the entire space, such a function is called the reentrant function. Otherwise become heavy milk can not function.

  Signal processing function, to try to ensure that reentrant functions.

#include<stdio.h>
#include<signal.h>
#include<unistd.h>
void doit(int n){
    int v;
    static int c=0;
    v=c;
    v++;
    usleep(5000);
    c=v;
    printf("c=%d\n",c);
    return;
}
int main(void){
    signal(2,doit);
    while(1){
        must ( 2 ); 
    } 
    Return  0 ; 
}

 Code, while loop 2 and signal processing functions called doit, both have read and write to c

Guess you like

Origin www.cnblogs.com/ptfe/p/11025430.html