mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: Problems with pthreads from a shared object?
Date: Wed, 7 Nov 2018 18:45:26 -0500	[thread overview]
Message-ID: <20181107234526.GW5150@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAHnO0JvhhEGesigEDvwQu4zHT=PKppYVGqzGmb2UEMC-_Z0rXQ@mail.gmail.com>

On Wed, Nov 07, 2018 at 06:40:35PM -0500, Barry Flartus wrote:
> Nope! Linux ubuntu-x64 4.4.0-116-generic -  this is just the kernel from a
> default Ubuntu 16.04 install.

OK. Can you run strace -f ./launch (or whatever the launch program
executable is called) and post the output?

Rich


> On Wed, Nov 7, 2018 at 6:31 PM Rich Felker <dalias@libc.org> wrote:
> 
> > On Wed, Nov 07, 2018 at 06:00:14PM -0500, Barry Flartus wrote:
> > > 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(&gthread, 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!
> >
> > Are you running on an ancient kernel or a kernel built with a lot of
> > default functionality configured out? These should be the only
> > conditions under which pthread_create can return ENOSYS.
> >
> > Rich
> >


  reply	other threads:[~2018-11-07 23:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-07 23:00 Barry Flartus
2018-11-07 23:31 ` Rich Felker
2018-11-07 23:40   ` Barry Flartus
2018-11-07 23:45     ` Rich Felker [this message]
2018-11-07 23:53       ` Barry Flartus
2018-11-08  0:43         ` Rich Felker
2018-11-08  1:02           ` Barry Flartus
2018-11-08  1:28             ` Rich Felker
2018-11-08  8:50           ` Jeffrey Walton
2018-11-08 14:53             ` Barry Flartus
2018-11-08 15:17               ` Rich Felker
2018-11-08 17:14                 ` Barry Flartus
2018-11-08 17:37                   ` Rich Felker
2018-11-08 17:56                     ` Barry Flartus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181107234526.GW5150@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).