- zmq::ctx_t::ctx_t (uint32_t io_threads_) :
-
tag (0xbadcafe0),
-
terminating (false)
-
{
。。。。。。
-
// Create I/O thread objects and launch them.
- /*
- 为什么i从2开始呢?这里的i是为slot的索引,在前面的代码中slot[0]为zmq_term对应的mailbox,即&term_ mailbox ,slot[1]为reaper线程对应的mailbox。所以I/O线程的mailbox的索引i只能从2开始。
这里创建并启动了I/O线程,并加入到slots中。
- */
-
for (uint32_t i = 2; i != io_threads_ + 2; i++) {
-
io_thread_t *io_thread = new (std::nothrow) io_thread_t (this, i);
-
alloc_assert (io_thread);
-
io_threads.push_back (io_thread);
-
slots [i] = io_thread->get_mailbox ();
-
io_thread->start ();
-
}
// In the unused part of the slot array, create a list of empty slots.
/* 如注释所言,保存空的slot 索引*/
for (int32_t i = (int32_t) slot_count - 1;
i >= (int32_t) io_threads_ + 2; i--) {
empty_slots.push_back (i);
slots [i] = NULL;
}
// Create the logging infrastructure.
log_socket = create_socket (ZMQ_PUB);
zmq_assert (log_socket);
rc = log_socket->bind ("sys://log");
zmq_assert (rc == 0);
- }