- extern "C"
-
{
-
static void *thread_routine (void *arg_)
-
{
-
#if !defined ZMQ_HAVE_OPENVMS
-
// Following code will guarantee more predictable latecnies as it'll
-
// disallow any signal handling in the I/O thread.
-
sigset_t signal_set;
-
int rc = sigfillset (&signal_set);
-
errno_assert (rc == 0);
-
# if !defined ZMQ_HAVE_ANDROID
-
rc = pthread_sigmask (SIG_BLOCK, &signal_set, NULL);
-
posix_assert (rc);
-
# endif
-
#endif
/* 本函数只是一个简单包装,这里直接调用thread_t的tfn,即调用者真正想启动的函数 */
-
zmq::thread_t *self = (zmq::thread_t*) arg_;
-
self->tfn (self->arg);
-
return NULL;
-
}
-
}
-
-
void zmq::thread_t::start (thread_fn *tfn_, void *arg_)
-
{
- /* 保存工作函数和参数 */
-
tfn = tfn_;
-
arg =arg_;
/*
创建线程,但是这里线程的入口函数并不是参数tfn_,为什么呢?
为什么不直接pthread_create(&descriptor, NULL, tfn_, arg)呢
*/
-
int rc = pthread_create (&descriptor, NULL, thread_routine, this);
-
posix_assert (rc);
-
}