I read the source code of Boost ASIO, and I wanna find out it is only one thread for it to call epoll_wait(Of course,if I use epoll reactor). I wanna find its solution about more than one thread to call epoll_wait, this may cause different threads doing the read for the same socket at the same time . I read some key codes as follows:
// Prepare to execute first handler from queue.
operation* o = op_queue_.front();
op_queue_.pop();
bool more_handlers = (!op_queue_.empty());
if (o == &task_operation_)
{
task_interrupted_ = more_handlers;
if (more_handlers && !one_thread_)
wakeup_event_.unlock_and_signal_one(lock);
else
lock.unlock();
task_cleanup on_exit = { this, &lock, &this_thread };
(void)on_exit;
// Run the task. May throw an exception. Only block if the operation
// queue is empty and we're not polling, otherwise we want to return
// as soon as possible.
task_->run(!more_handlers, this_thread.private_op_queue);
}
task_ is epoll reactor and it will call epoll_wait in the run, I guess it may only one thread to call it because only one "task_operation_" in the op_queue_, am I right ? If I wanna use epoll in multi-threading, or I may use "EPOLLONESHOT" so that it can ensure that one thread handle one socket at one time. Can anyone help ? please, thanks.
Aucun commentaire:
Enregistrer un commentaire