bug-gdb
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

pthread debugging issues


From: Justin A Irwin
Subject: pthread debugging issues
Date: Tue, 27 Mar 2001 18:12:05 -0700

First of all, I apologize if these are known issues, but I haven't found
any corroborating evidence of my problems, so I thought it was best to be
on the safe side and report them.

I have recently been working on porting some internal software to
GNU/Linux, and have had a couple of problems with using gdb and
LinuxThreads. The program I have included at the end of my e-mail produces
two different undesirable behaviors on different machines/releases. Two
birds with one stone, as it were.

The first problem I have found involves:
IBM NetVista machine:
-Intel PIII 866
-S3 Trio64V+ PCI video card (the integrated Intel 815 chipset worked
terribly under Linux)
-IBM PCI token ring card
RedHat Linux 6.2 (should be the stock version; the ISO images came off of
an internal server):
-kernel 2.2.14-5.0
-gcc egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
-gdb 19991004 configured for i386-redhat-linux

The problem I've been having is, gdb will hang the first time
pthread_create() is called. This doesn't just happen out of nowhere,
though. There is some code that first sets the pthread signal mask to block
all signals, then re-enables the signals that we want the initial thread to
handle. I was able to distill this behavior down to a small example that
simply blocks all signals and then calls pthread_create(). Running on its
own, the program executes normally. However, in gdb, it hangs at the call
to pthread_create(). I re-enabled ^C, and interrupting the program when it
hangs will allow the program to continue. As a horrible hack of a fix ;), I
deleted signal 34 from the set of signals to block. This allows the program
to behave normally under gdb.

We were also interested in trying a 2.4 kernel. So, I set up SuSE on
another machine:
IBM Personal Computer 365
- Intel PPRO 200
- S3 Trio64V+ PCI video card
- IBM ISA token ring card
SuSE Linux 7.1 Professional (should be the stock version; the ISO images
came off of an internal server):
- kernel 2.4.0-4GB
- gcc 2.95.2 19991024 (release)
- gdb 5.0 configured for i386-suse-linux

I was quite happy when I first ran gdb on my program and it didn't hang
when the first threads were created. Unfortunately, the honeymoon didn't
last long ;). The first time a thread exited, I was greeted with "Program
exited normally." The program did not, in fact, exit normally; there were a
good half-dozen threads still hanging around. I had to kill the first one
off with kill -9, then the rest disappeared on their own. So, I tried gdb
with my faithful deadlock program, and I was able to repeat that same
behavior. Running deadlock on its own produces the correct output. I have
yet to find a workaround for this. However, I should qualify: Linux has not
been running well on this machine in general.

I'm required to use Lotus Notes for mail, so the best way for me to attach
deadlock.c was inline. I hope this is okay.

Compiling:
> gcc -D_REENTRANT -g -o deadlock deadlock.c -lpthread

To test, just run deadlock. It should produce the following output:
> ./deadlock
> Worker function started.
> Worker function finished.

With RedHat 6.2, running gdb on deadlock hangs before it prints anything.
Press ^C and then type 'c' and it should finish.

With SuSE 7.1, running gdb on deadlock gives the following output:
> Worker function started.
>
> Program exited normally.

I appreciate any help. Many of my co-workers would like to go back to using
Windows NT and I'd prefer to move on with Linux, so I hate to give them any
more fuel ;)

-J

Justin A. Irwin
Defender of the Universe
Dept. LBRA
Email: address@hidden

-------- cut here --------
/*
 * Justin A. Irwin/IBM
 * address@hidden
 *
 * deadlock.c - Smallest possible program to demonstrate deadlock behavior
 *              in gdb + pthreads with stock RedHat 6.2
 *            - Also demonstrates premature exit behavior in gdb +
 *              pthreads with stock SuSE 7.1
 *
 * To compile: gcc -D_REENTRANT -g -o deadlock deadlock.c -lpthread
 */

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

/* Uncomment this line for RedHat 6.2 workaround */
/*#define RH62_FIX*/

void *worker_func(void *arg)
{
  printf("Worker function started.\n");

  pthread_exit(0);
}

int main(int argc, char **argv)
{
  pthread_t worker;
  sigset_t  blockedSigs;

  /* Get the full signal set */
  sigfillset(&blockedSigs);

  /* Allow ^C */
  sigdelset(&blockedSigs, SIGINT);

#ifdef RH62_FIX
  /* Delete r.t. signal 34 from the set */
  sigdelset(&blockedSigs, 34);
#endif /* RH62_FIX */

  /* Block all signals (except, possibly, 34) */
  pthread_sigmask(SIG_BLOCK, &blockedSigs, NULL);

  /* Create the new thread; this should deadlock in gdb with RedHat 6.2 */
  pthread_create(&worker, NULL, worker_func, NULL);

  /* Rejoin with worker thread */
  pthread_join(worker, NULL);

  /* SuSE 7.1 never gets here; instead, it says "Program exited normally."
*/
  printf("Worker function finished.\n");

  return 0;
}
/* deadlock.c */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]