ipc--Thread Signal problem

Source: Internet
Author: User

All threads share the same signal processing method

The main thread sets the processing mode of the SIGINT signal in order to capture, then all the secondary threads share this processing, and if one of the threads changes the way the signal is processed, then all the threads will share the change.

Recalling "signal shielding word" and "pending signal word"

Role

"Signal shielding word" and "pending signal word" function with process signal, reference ipc--signal

Modify the signal mask character function

int Sigemptyset (sigset_t *set);

int Sigfillset (sigset_t *set);

int Sigaddset (sigset_t *set, int signum);

int Sigdelset (sigset_t *set, int signum);

int sigprocmask (int how, const sigset_t *set, sigset_t *oldset);

When there is no secondary thread

At this time the entire process has only one main thread, the whole process of "signal shielding word" and "pending signal word", is the main thread "signal shielding word" and "pending signal word."

When a thread is available

Each sub-thread has its own independent "signal screen word" and "pending signal word", the second thread of "signal shielding word" and "pending signal word" is copied from the main thread "signal shielding word" and "pending signal word", at the time of copying,

(1) The "signal screen word" of the secondary thread retains the value copied from the main thread "signal mask word".

(2) The "pending signal word" of the secondary thread is emptied, meaning that the copied value is not preserved.

If the secondary thread has a special "response requirement" for some signals, it can call the following function and modify the secondary thread's own "signal mask word" to enable a signal to be opened or blocked.

int Sigemptyset (sigset_t *set);

int Sigfillset (sigset_t *set);

int Sigaddset (sigset_t *set, int signum);

int Sigdelset (sigset_t *set, int signum);

int sigprocmask (int how, const sigset_t *set, sigset_t *oldset);

How does multi-threading respond to a signal?

(1) After the process receives the signal, the process will find a thread that does not mask the signal to handle which thread is being searched for in this signal, and the process is the boss.

(2) If all the threads are blocking the signal, the process will record the pending signal to a thread's "pending signal word" when the signal occurs. Similarly, which thread to find, the process is the boss.

(3) When the thread receives the signal that the process has awarded it, and if the signal is processed or captured, the thread is interrupted at run time, then executes the signal capture function, and when the signal capture function is finished, it returns the interrupted thread and executes.

ipc--Thread Signal problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.