Does anyone know if I can call epoll.register from another thread safely?
Here is what I am imagining:
- Thread 1: epoll.poll()
- Thread 2: adding some fd to the same epoll object with epoll.register
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I changed my answer after you changed the question.
This will not be “thread safe” in that each thread will impact the same epoll object. Registering a new fd to the epoll object will still do it to that object.
There’s no reason for that particular object to have different states across separate threads, because in that scenario one should made one object for each thread.
So, short answer: Your setup will work.
In fact, the python stdlib http.server package uses that same method (just using poll instead of epoll). It creates a polling object in one thread, and uses a separate thread to poll it.