Skip to content

Commit

Permalink
Merge pull request #13052 from OlivierNicole/atomic_max_stack_sz
Browse files Browse the repository at this point in the history
Make caml_max_stack_wsize atomic to avoid a data race
  • Loading branch information
gasche authored Mar 27, 2024
2 parents 83535fc + bb9816c commit 5fe8065
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion runtime/caml/gc_ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "misc.h"

CAMLextern uintnat caml_max_stack_wsize;
CAMLextern atomic_uintnat caml_max_stack_wsize;
CAMLextern uintnat caml_fiber_wsz;
CAMLextern uintnat caml_major_cycles_completed;

Expand Down
3 changes: 2 additions & 1 deletion runtime/fiber.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,9 @@ int caml_try_realloc_stack(asize_t required_space)
old_stack = Caml_state->current_stack;
stack_used = Stack_high(old_stack) - (value*)old_stack->sp;
wsize = Stack_high(old_stack) - Stack_base(old_stack);
uintnat max_stack_wsize = caml_max_stack_wsize;
do {
if (wsize >= caml_max_stack_wsize) return 0;
if (wsize >= max_stack_wsize) return 0;
wsize *= 2;
} while (wsize < stack_used + required_space);

Expand Down
4 changes: 2 additions & 2 deletions runtime/gc_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "caml/startup.h"
#include "caml/fail.h"

uintnat caml_max_stack_wsize;
atomic_uintnat caml_max_stack_wsize;
uintnat caml_fiber_wsz;

extern uintnat caml_percent_free; /* see major_gc.c */
Expand Down Expand Up @@ -335,7 +335,7 @@ void caml_init_gc (void)
caml_percent_free = norm_pfree (caml_params->init_percent_free);
caml_gc_log ("Initial stack limit: %"
ARCH_INTNAT_PRINTF_FORMAT "uk bytes",
caml_max_stack_wsize / 1024 * sizeof (value));
caml_params->init_max_stack_wsz / 1024 * sizeof (value));

caml_custom_major_ratio =
norm_custom_maj (caml_params->init_custom_major_ratio);
Expand Down

0 comments on commit 5fe8065

Please sign in to comment.