Spaces:
Paused
Paused
| int thread_num = 4; | |
| hloop_t** worker_loops = NULL; | |
| void init_loop(int _thread_num, hthread_routine worker_thread) { | |
| thread_num = _thread_num; | |
| worker_loops = (hloop_t**)malloc(sizeof(hloop_t*) * thread_num); | |
| for (int i = 0; i < thread_num; ++i) { | |
| worker_loops[i] = hloop_new(HLOOP_FLAG_AUTO_FREE); | |
| hthread_create(worker_thread, worker_loops[i]); | |
| } | |
| } | |
| hloop_t* get_next_loop() { | |
| static int s_cur_index = 0; | |
| if (s_cur_index == thread_num) { | |
| s_cur_index = 0; | |
| } | |
| return worker_loops[s_cur_index++]; | |
| } |