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
Does anyone know if I can call epoll.register from another thread safely?
Here is what I am imagining:
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.