static void _start(int thread) { pthread_t pid[thread+2]; struct monitor *m = skynet_malloc(sizeof(*m)); M = 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); } create_thread(&pid[0], _monitor, m); create_thread(&pid[1], _timer, m); //create_thread(&pid[2], _socket, m); skynet_socket_start_thread(); struct worker_parm wp[thread]; for (i=0;i<thread;i++) { wp[i].m = m; wp[i].id = i; create_thread(&pid[i+2], _worker, &wp[i]); } for (i=0;i<thread+2;i++) { pthread_join(pid[i], NULL); } free_monitor(m); }
static void _start(int thread) { pthread_t pid[thread+2]; struct monitor *m = malloc(sizeof(*m)); m->count = thread; m->m = malloc(thread * sizeof(struct skynet_monitor *)); int i; for (i=0;i<thread;i++) { m->m[i] = skynet_monitor_new(); } pthread_create(&pid[0], NULL, _monitor, m); pthread_create(&pid[1], NULL, _timer, NULL); for (i=0;i<thread;i++) { pthread_create(&pid[i+2], NULL, _worker, m->m[i]); } for (i=1;i<thread+2;i++) { pthread_join(pid[i], NULL); } }