multithreading - Using sigprocmask to implement locks -


I am implementing the user thread in Linux kernel 2.4, and I want to open the context switch between the thread ualarm I am using.

We have a requirement that the functions of our thread libraries should be incompatible with the reference switching mechanism for threads, so I looked in the blocking signals and learned that this is the standard way to use seagprocmask.

However, it seems that I need to do a lot to implement it:

  sigset_t new_set, old_set; Sigemptsset (& new_set); Signal (and new_set, SIGALRM); Sigprocmask (SIG_BLOCK, & amp; new_set, & old_set);  

This block SIGALARM but it does 3 function with invocation! There may be a lot of time to run these tasks, including sending the signal. The best idea I had to do to reduce it was temporarily disabled like ualarm, such as:

  sigset_t new_set, old_set; Time = ualarm (0,0); Sigemptsset (& new_set); Signal (and new_set, SIGALRM); Sigprocmask (SIG_BLOCK, & amp; new_set, & old_set); Ualarm (time, 0);  

Besides that, it seems literally that there is no better way to do this?

As indicated, signal set functions are quite light and are also applied as a macro Can; And you can keep only a signal set which contains only SIGALRM and reuse it.

Regardless, this does not actually matter the signal would be sigaddset () or sigemptyset () during the call - The new_set and old_set variables (possibly) are thread-locals, and important sections sigprocmask () are not entered until after the return .


Comments