I'm writing a server program in C for academic purpose.
The server lunch a fixed number of worker thread during initialization then the threads start waiting on a "request list".
After that the server starts an infinite cycle where it must do these two things:
- Check for new connections
- Check for possible
read()
on connected clients (only through select/poll not epoll) and remove all readable file descriptors from the set (fd_set in the case we usedselect()
orstruct pollfd*
in the case we used poll) and put it in the list where the threads are waiting.
In this way worker threads will extract requests from list and serve them.
Each request require undefined sequence of read()
and write()
call.
All I would like to understand if exists a threadsafe way for adding and removing file descriptor from the fd_set
or the struct pollfd*
.