Home > Software design >  Is libpthread needed if the pthread API is in libc
Is libpthread needed if the pthread API is in libc

Time:01-21

Looking at the output of readelf -s /lib/x86_64-linux-gnu/libc.so.6 on my Ubuntu 22.04 box, I see (what looks to be) the entire pthread API contained in the .text section.

As a sanity check, I successfully compiled and ran

#include <stdio.h>
#include <string.h>

#include <pthread.h>

static void *
func(void *args) {
    return args;
}

int main() {
    int ret;
    pthread_t thread;

    ret = pthread_create(&thread, NULL, func, NULL);
    if ( ret != 0 ) {
        fprintf(stderr, "pthread_create: %s\n", strerror(ret));
        return ret;
    }
    pthread_join(thread, NULL);

    return 0;
}

without using -pthread.

Given all of this, is there any purpose to libpthread on my computer other than providing support for older applications which expect it to be there?

CodePudding user response:

Is libpthread needed if the pthread API is in libc

No.

is there any purpose to libpthread on my computer other than providing support for older applications which expect it to be there?

No.

See https://developers.redhat.com/articles/2021/12/17/why-glibc-234-removed-libpthread . Since then libpthread is an empty library.

  • Related