[Bug 150959] [libc] Stub pthread_once in libc should call _libc_once

From: <bugzilla-noreply_at_freebsd.org>
Date: Mon, 13 Apr 2026 18:05:45 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=150959

--- Comment #7 from Ed Maste <emaste@freebsd.org> ---
The bug of pthread_once returning 0 but not calling the function is indeed
fixed -- pthread_once now returns an error and does not call the function.


#include <stdbool.h>
#include <stdio.h>
#include <pthread.h>

static pthread_once_t once = PTHREAD_ONCE_INIT;
static bool called;

static void
init(void)
{
        called = true;
}

int main(void)
{
        int ret = pthread_once(&once, init);
        printf("pthread_once returned %d, init was %scalled\n", ret,
            called ? "" : "not ");
}

$ cc repro.c && ./a.out
pthread_once returned 78, init was not called

It would be nice if we can still improve things as @jhb suggests

-- 
You are receiving this mail because:
You are the assignee for the bug.