|   | 
| 
 | 
Message-ID: <CAHnO0JtBcYitENkyfoR9itNgw0ja-dVmOkiyjTEm99POYBut+w@mail.gmail.com>
Date: Wed, 7 Nov 2018 18:00:14 -0500
From: Barry Flartus <barry.flartus@...il.com>
To: musl@...ts.openwall.com
Subject: Problems with pthreads from a shared object?
Hello,
I am encountering some issues that I believe are musl related when trying to
use pthreads from a shared object. Below is a minimal example (2 files) of
the problem.
==================== test.c ====================
// Compile with
// musl-gcc -Wall -lpthread -shared -fPIC test.c -o test.so
#include <pthread.h>
#include <stdio.h>
static void *launch(void *arg);
int start_thread(void);
void entry_point(void) __attribute__((constructor));
static pthread_t gthread;
static void *launch(void *arg)
{
    for (int i = 0; i < 4; i++){
        printf("[%d] Hello from the thread\n", i);
    }
    return NULL;
}
int start_thread(void)
{
    printf("Starting the thread\n");
    return pthread_create(>hread, NULL, launch, NULL);
}
void entry_point(void){
    puts("Starting Execution");
    int res = start_thread();
    printf("start_thread returned %d\n", res);
    if (res == 0){
        pthread_join(gthread, NULL);
    } else {
        printf("pthread_create() returned an error. Aborting.\n");
    }
}
==================== launch.c ====================
// Compile with:
// gcc launch.c -ldl -o launch
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
int main(){
    void *handle;
    puts("\nLaunching test...");
    handle = dlopen("./test.so", RTLD_NOW);
    if (!handle) {
        fprintf(stderr, "%s\n", dlerror());
        exit(EXIT_FAILURE);
    }
    dlerror();
    return EXIT_SUCCESS;
}
When the above examples are compiled with gcc, everything works correctly
and
produces the following output:
Launching test...
Starting Execution
Starting the threadstart_thread returned 0
[0] Hello from the thread
[1] Hello from the thread
[2] Hello from the thread
[3] Hello from the thread
When I switch to musl pthread_create() returns the integer '38', which is an
undocumented return value. I assume this corresponds with ENOSYS from
errno.h
but I can't seem to figure out why this is happening.
Output:
Launching test...
Starting Execution
Starting the thread
start_thread returned 38
pthread_create() returned an error. Aborting.
Is this even supported by musl? If so, where have I gone wrong?
Thanks in advance!
Content of type "text/html" skipped
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.