Hi, t...@!

I've been trying to test rthreads and have hit some weird races
using simple tests:

% cat rth.c
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include <err.h>

pthread_t worker;
pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;

void *
worker_run(void *arg)
{
        pthread_self();
        return (NULL);
}

int
main(int argc, char **argv)
{
        if (pthread_create(&worker, NULL, worker_run, NULL) != 0)
                err(1, "pthread_create");

        return (0);
}

I get this segfault almost always:

#0  pthread_exit (retval=0x0) at /usr/src/lib/librthread/rthread.c:223
223             for (clfn = thread->cleanup_fns; clfn; ) {
(gdb) bt
#0  pthread_exit (retval=0x0) at /usr/src/lib/librthread/rthread.c:223
#1  0x05716294 in _rthread_start (v=Could not find the frame base for
"_rthread_start".
) at /usr/src/lib/librthread/rthread.c:100
#2  0x05717be9 in rfork_thread () from /usr/lib/librthread.so.4.1
#3  0x21fb6b94 in ?? () from /usr/lib/libc.so.57.0
#4  0x3c00325f in __progname_storage ()
#5  0x3c003160 in environ ()
#6  0xcfbccc84 in ?? ()
#7  0x064c3b27 in _dl_bind_start () from /usr/libexec/ld.so
#8  0x87cd62e4 in ?? ()
#9  0x00000478 in ?? ()
#10 0xcfbc0033 in ?? ()
#11 0x064c0033 in ?? ()
#12 0x3c003160 in environ ()
#13 0x3c00325f in __progname_storage ()
#14 0xcfbccc84 in ?? ()
#15 0x21fb6b94 in ?? () from /usr/lib/libc.so.57.0
#16 0x00000000 in ?? ()

When trying to run the program in gdb I get weird stuff like:

(gdb) break worker_run
Breakpoint 1 at 0x1c000806: file /home/proger/rthreads/rth.c, line 12.
(gdb) start
Breakpoint 2 at 0x1c0007a0: file /home/proger/rthreads/rth.c, line 21.
Starting program: /home/proger/rthreads/obj/rth 
main () at /home/proger/rthreads/rth.c:21
21      {
(gdb) n
main () at /home/proger/rthreads/rth.c:22
22              if (pthread_create(&worker, NULL, worker_run, NULL) != 0)
(gdb) n

Program received signal ?, Unknown signal.
0x1c0007d6 in main () at /home/proger/rthreads/rth.c:22
22              if (pthread_create(&worker, NULL, worker_run, NULL) != 0)
(gdb) n
warning: Signal ? does not exist on this system.

Program received signal SIGKILL, Killed.
0x1c0007d6 in main () at /home/proger/rthreads/rth.c:22
22              if (pthread_create(&worker, NULL, worker_run, NULL) != 0)


kdump | tail is:

31222 rth      CALL  getthrid()         # child
31222 rth      RET   getthrid 1031222/0xfbc36
15365 rth      CALL  mprotect(0x2494c000,0x1000,0x1)
31222 rth      PSIG  SIGSEGV SIG_DFL code 1 addr=0x8c trapno=1
31222 rth      NAMI  "rth.core"
15365 rth      PSIG  SIGKILL SIG_DFL code 0

Looks like some stupid race with two threads exiting at almost same
time? Any ideas on tracking it down?

By the way, is such gdb behaviour normal? Does it need any additional
patching before being useful to debug software using rthreads?

Thanks!

Reply via email to