Libevent source code in-depth analysis 13th-notes for libevent Signal Processing

Source: Internet
Author: User

Libevent

Source code in-depth analysis 13


--

Libevent

Signal Processing notes


As mentioned above
Libevent
Multiple Threads are implemented. However, when registering a signal event in a multi-threaded environment, you must be careful when dealing with the event.
Libevent
Register a signal event on the instance. Append the title
Libevent
Series.

 

To
2
For example, to do a simple scenario analysis.

1
First, create and initialize a thread.
1
Of
Libevent
Instance
Base1
, Thread
1
Of
Libevent
Instance
Base2
;

2
In
Base1
Register on
Sigalrm
Signal; in
Base2
Register on
SIGINT
Signal;

3
Assume that the current
Base1
And
Base2
No other events are registered;

4
Thread
1
And
2
All
Event_base_loop
Event loop:

Event_base_loop (base1)



Event_base_loop (base2)

{



{

If (base2-> Sig. ev_signal_added)


If (base2-> Sig. ev_signal_added)

Evsignal_base = base1;

 


Evsignal_base = base2;

While (! Done)


While (! Done)

{

{


...



...


Evsel-> dispatch (...);


Evsel-> dispatch (...);


...


...

}



}

}


}

5
Suppose thread
1
Enter
Event_base_loop
And set
Evsignal_base = base1
; And wait;

6
Next thread
2
Also enter
Event_base_loop
And set
Evsignal_base = base2
; And wait;



Therefore
Evsignal_base
Point
Base2
;

7
Signal
Alarm
Trigger, call the service routine:

Static void evsignal_handler (INT sig)

{


...


Evsignal_base-> Sig. evsigcaught [sig] ++;


Evsignal_base-> Sig. evsignal_caught
= 1;


/*
Wake up our notification mechanic */


Send (evsignal_base-> Sig. ev_signal_pair [0],
"A", 1, 0 );


...

}

Therefore
Base2
Notified
Alarm
The signal happened, but actually
Alarm
Yes registered in
Base1
On,
Base2
On
Alarm
Register
Event
It is null, so the handler cannot be called;

 

Therefore
Libevent
To process the signal, you can only register the signal to one
Libevent
Instance.

Memcached
No
Libevent
Provided
Signal
Interface, but directly use the native
API
, It looks more concise.

 

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.