Linux multi-thread Signal

Source: Internet
Author: User
Linux multi-thread signal-Linux general technology-Linux programming and kernel information. The following is a detailed description. In POSIX.1 model, after an asynchronous signal is sent to a process, a thread in the process that does not block the signal is selected to receive the signal. When implementing an application based on the event model, you can use pthread_sigmash to block those signals. But linux does not comply with this rule. linux threads are independent. When we use the POSIX model to send signals to processes, we will find that the signals are lost.

The solution to this problem is to directly send a signal to the thread. Use the gettid function to obtain the thread id. Because glibc does not provide gettid, You Need To encapsulate it yourself, as shown below.

# Include
Pid_t gettid ()
{
Return syscall (SYS_gettid );
}

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.