Skip to content

Commit

Permalink
race condition fix
Browse files Browse the repository at this point in the history
many thanks to Jonathan Protzenko
who detected it on a high-end machine
  • Loading branch information
Antonin Reitz committed Oct 17, 2023
1 parent db25dda commit 60b818b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib-alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#define N_ARENA 4

static uint32_t init_status = 0UL;
static atomic_uint init_status = 0UL;
static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;

__attribute__((tls_model("initial-exec")))
Expand All @@ -25,9 +25,9 @@ uint8_t* StarMalloc_memset_u8(uint8_t* dest, uint8_t v, size_t n) {

void* malloc(size_t size) {
if (! init_status) {
init_status=1UL;
pthread_mutex_lock(&m);
krmlinit_globals();
init_status=1UL;
pthread_mutex_unlock(&m);
}
if (thread_arena == N_ARENA) {
Expand Down

0 comments on commit 60b818b

Please sign in to comment.