public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* thread cannot stop himself
@ 2001-02-08  5:58 Nicolas Vignal
  2001-02-09  3:36 ` Mark Kettenis
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Vignal @ 2001-02-08  5:58 UTC (permalink / raw)
  To: gdb

Hello

I join a sample program with a thread who try to stop himself with a SIGSTOP. 
( I know that is not the best way to do that ;-)
It works fine in command line but not under gdb.
gdb receive the signal and the flag pass to program is yes. But the thread 
never stop.

Any idea of what happened ?

Regards


	Nicolas


I'am using a Linux RedHat 6.2 with insight 20010202

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


int function(void)
{
  printf("I want to stop this thread\n");
  pthread_kill(pthread_self(), SIGSTOP);
  while(1){
   printf("Why it's not working ?\n");
  }
}

int main(int argc, char *argv[])
{

  pthread_t threadID=-1;
  pthread_create(&threadID, NULL, function, NULL);

  while(1);
  return 0;
}


(gdb) run
Starting program: /home/tsc/essai/stopthread
[New Thread 1024 (runnable)]
[New Thread 2049 (runnable)]
[New Thread 1026 (runnable)]

Program received signal SIGSTOP, Stopped (signal).
[Switching to Thread 1026 (runnable)]
0x4004dd41 in __kill () from /lib/libc.so.6

(gdb) handle SIGSTOP
Signal        Stop	Print	Pass to program	Description
SIGSTOP       Yes	Yes	Yes		Stopped (signal)

(gdb) c
Continuing.

After I can see "Why it's not working ?" in loop

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: thread cannot stop himself
  2001-02-08  5:58 thread cannot stop himself Nicolas Vignal
@ 2001-02-09  3:36 ` Mark Kettenis
  2001-02-12  7:10   ` Nicolas Vignal
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Kettenis @ 2001-02-09  3:36 UTC (permalink / raw)
  To: Nicolas Vignal; +Cc: gdb

Nicolas Vignal <nicolas.vignal@netline.fr> writes:

> Hello
> 
> I join a sample program with a thread who try to stop himself with a
> SIGSTOP.
> ( I know that is not the best way to do that ;-)
> It works fine in command line but not under gdb.
> gdb receive the signal and the flag pass to program is yes. But the thread 
> never stop.
> 
> Any idea of what happened ?

GDB uses SIGSTOP internally (for stopping threads) which interferes
horribly with your own use of the signal.  I'm loooking into a
solution, but things are pretty hairy, and I can't guarantee that I
find an acceptable solution to the problem.

For now, the only advice I can give you is: don't use SIGSTOP.  I'm
not sure what you're trying to accomplish by having a thread stop
itself, but there should be an alternative to using signals.  Try
using a mutex, semaphore or perhaps poll/select.

Mark

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: thread cannot stop himself
  2001-02-09  3:36 ` Mark Kettenis
@ 2001-02-12  7:10   ` Nicolas Vignal
  0 siblings, 0 replies; 3+ messages in thread
From: Nicolas Vignal @ 2001-02-12  7:10 UTC (permalink / raw)
  To: Mark Kettenis, gdb; +Cc: gdb

Thanks for your answer, I found this messages in the mailing list 

http://sources.redhat.com/ml/gdb/2000-10/msg00001.html

still you ;-)

I will try to use less SIGSTOP but I need a way to stop threads.

Regards

	Nicolas

On Friday 09 February 2001 12:36, Mark Kettenis wrote:
> Nicolas Vignal <nicolas.vignal@netline.fr> writes:
> > Hello
> >
> > I join a sample program with a thread who try to stop himself with a
> > SIGSTOP.
> > ( I know that is not the best way to do that ;-)
> > It works fine in command line but not under gdb.
> > gdb receive the signal and the flag pass to program is yes. But the
> > thread never stop.
> >
> > Any idea of what happened ?
>
> GDB uses SIGSTOP internally (for stopping threads) which interferes
> horribly with your own use of the signal.  I'm loooking into a
> solution, but things are pretty hairy, and I can't guarantee that I
> find an acceptable solution to the problem.
>
> For now, the only advice I can give you is: don't use SIGSTOP.  I'm
> not sure what you're trying to accomplish by having a thread stop
> itself, but there should be an alternative to using signals.  Try
> using a mutex, semaphore or perhaps poll/select.
>
> Mark

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-02-12  7:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-02-08  5:58 thread cannot stop himself Nicolas Vignal
2001-02-09  3:36 ` Mark Kettenis
2001-02-12  7:10   ` Nicolas Vignal

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 read-only IMAP folder(s) and NNTP newsgroup(s).