skynet线程启动:
1、线程监控初始化:
struct monitor *m = skynet_malloc(sizeof(*m));
memset(m, 0, sizeof(*m));
m->count = thread;
m->sleep = 0;
m->m = skynet_malloc(thread * sizeof(struct skynet_monitor *));
int i;
for (i=0;i<thread;i++) {
m->m[i] = skynet_monitor_new();
}
if (pthread_mutex_init(&m->mutex, NULL)) {
fprintf(stderr, "Init mutex error");
exit(1);
}
if (pthread_cond_init(&m->cond, NULL)) {
fprintf(stderr, "Init cond error");
exit(1);
}
2、监控线程创建:
create_thread(&pid[0], thread_monitor, m );
3、创建定时器线程:
create_thread(&pid[1], thread_timer, m);
4、创建socket线程:
create_thread(&pid[2], thread_socket, m);
5、创建8个工作线程:
create_thread(&pid[i+3], thread_worker, &wp[i]);
6、等待所有线程结束:
pthread_join(...)