Skip to content

Commit 321a540

Browse files
committed
fix #391: idx out of range
1 parent c0f8fba commit 321a540

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

evpp/EventLoopThreadPool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class EventLoopThreadPool : public Status {
3434
int idx = 0;
3535
if (lb == LB_RoundRobin) {
3636
if (++next_loop_idx_ >= numLoops) next_loop_idx_ = 0;
37-
idx = next_loop_idx_.fetch_and(numLoops);
37+
idx = next_loop_idx_ % numLoops;
3838
} else if (lb == LB_Random) {
3939
idx = hv_rand(0, numLoops - 1);
4040
} else if (lb == LB_LeastConnections) {

examples/multi-thread/one-acceptor-multi-workers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ static hloop_t** worker_loops = NULL;
1919

2020
static hloop_t* get_next_loop() {
2121
static int s_cur_index = 0;
22-
if (s_cur_index == thread_num) {
22+
if (++s_cur_index >= thread_num) {
2323
s_cur_index = 0;
2424
}
25-
return worker_loops[s_cur_index++];
25+
return worker_loops[s_cur_index % thread_num];
2626
}
2727

2828
static void on_close(hio_t* io) {

0 commit comments

Comments
 (0)