Skip to content

Commit 18aaf94

Browse files
committed
Merge pull request atomvm#1414 from pguyot/w52/fix-race-condition-wait
Fix an issue where a timeout could be triggered immediately If a message arrived between `loop_rec` and `wait_timeout`, the execution didn't resume to testing the received message but instead proceeded to the `timeout` opcode. As a result, a timeout occurred immediately. Fixes atomvm#1412 These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 546ac2b + 5cef765 commit 18aaf94

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ might lead to a crash in certain situations.
2424
- Fix corruption when dealing with specific situations that involve more than 16 x registers when
2525
certain VM instructions are used.
2626
- Fixed ESP32 GPIO interrupt trigger `none`
27+
- Fixed an issue where a timeout would occur immediately in a race condition
2728

2829
## [0.6.5] - 2024-10-15
2930

src/libAtomVM/opcodesswitch.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,14 +2551,13 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
25512551
}
25522552

25532553
if (needs_to_wait) {
2554-
ctx->saved_ip = saved_pc;
25552554
#pragma GCC diagnostic push
25562555
#pragma GCC diagnostic ignored "-Wpedantic"
25572556
ctx->restore_trap_handler = &&wait_timeout_trap_handler;
25582557
#pragma GCC diagnostic pop
2559-
ctx->saved_module = mod;
2560-
ctx = scheduler_wait(ctx);
2561-
goto schedule_in;
2558+
SCHEDULE_WAIT(mod, saved_pc);
2559+
} else {
2560+
JUMP_TO_ADDRESS(mod->labels[label]);
25622561
}
25632562
#endif
25642563

@@ -3193,10 +3192,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
31933192
if (LIKELY(remaining_reductions)) {
31943193
JUMP_TO_ADDRESS(mod->labels[label]);
31953194
} else {
3196-
ctx->saved_ip = mod->labels[label];
3197-
ctx->saved_module = mod;
3198-
ctx = scheduler_next(ctx->global, ctx);
3199-
goto schedule_in;
3195+
SCHEDULE_NEXT(mod, mod->labels[label]);
32003196
}
32013197
#endif
32023198
break;
@@ -6394,7 +6390,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
63946390
case OP_RECV_MARKER_CLEAR: {
63956391
DEST_REGISTER(reg_a);
63966392
DECODE_DEST_REGISTER(reg_a, pc);
6397-
TRACE("recv_marker_clean/1: reg1=%c%i\n", T_DEST_REG(reg_a));
6393+
TRACE("recv_marker_clear/1: reg1=%c%i\n", T_DEST_REG(reg_a));
63986394
break;
63996395
}
64006396

0 commit comments

Comments
 (0)