Re: Problem with pthread_kill, maybe bug?

"Saurabh Desai" <[email protected]>
Newsgroups gmane.linux.ngpt.devel
Message-ID <[email protected]>

Yes, this is a real problem in NGPT. Looks like when a thread is in
wait_queue,
the pthread_kill() gets ignored. We will investigate more in detail and fix
it soon.

Thanks for reporting this and providing a testcase.

- - - - -
Saurabh Desai
POSIX Threading for Linux
IBM  Linux Technology Center
e-mail: [email protected] OR [email protected]
phone: 512-838-2655, T/L: 678-2655
http://oss.software.ibm.com/developerworks/opensource/pthreads



Christophe Saout <[email protected]>@www-124.southbury.usf.ibm.com on
08/23/2002 08:08:55 AM

Sent by:    [email protected]


To:    [email protected]
cc:
Subject:    [pthreads-devel] Problem with pthread_kill, maybe bug?


Hi!

Sorry for resending it in this mailing list but I didn't get an answer
on pthreads-users.

I compiled mysqld with ngpt 2.0.1 and got problems shutting down the
server (via kill or mysqladmin). I think it's not mysql's fault since it
works fine with several other pthreads implementations (not only
LinuxThreads - it has some LinuxThread workarounds but only uses them
when LinuxThreads is being used). After some debugging I found out that
the problem has something to do with the use of signals and pthread_kill
in the code shutting down the server.

I have written a test program that simulates the problem and now believe
that it actually is a NGPT bug.

Look at this:

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

pthread_t main_thread;

static int killed = 0;

void boum(int signum)
{
   killed = 1;
   printf("Try to kill main thread (%d)\n", signum);
   pthread_kill(main_thread, SIGUSR1);
}

void *subthread(void *arg)
{
   printf("Subthread start\n");
   sleep(5);
   printf("Subthread sleep aborted\n");
   if (!killed)
      boum(-1);
   return NULL;
}

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

   signal(SIGINT, boum);
   main_thread = pthread_self();
   if (argc > 1)
      pthread_create(&slave_thread, NULL, subthread, NULL);
   select(0, NULL, NULL, NULL, NULL); /* Wait forever */
   pthread_join(slave_thread, NULL);
   return 0;
}
----------

You can perform three tests with this small program:

1. Run it without argument (on the console)
It will wait forever (in the select line).
Now you can send it a SIGINT (e.g. by pressing ^C).
The signal handler is run, which in turn sends a SIGUSR1, which isn't
handled and the program should abort with (User defined signal 1) or
something.
This works as expected with both LinuxThreads and NGPT (2.0.1).

2. Run it with an argument (no matter what).
A child thread is created which waits for five seconds and then sends
the main process a SIGUSR1.
You should expect that the program aborts. It does with LinuxThreads
(after five seconds), again with "User defined signal 1", but with NGPT
nothing happens (the signal is lost somewhere).

3. Run it with an argument and send a SIGINT within five seconds
If you send a SIGINT while the child thread is waiting in sleep(5), the
signal handler for SIGINT is called which in turn tries to kill the main
process.
You should expect that the same thing happens as without the command
line argument (without the child thread). With LinuxThreads again, it
works fine (just like the first test). But with NGPT the signal handler
gets called but the SIGUSR1 doesn't arrive in the main thread. Instead
of that you can see that sleep(5) in the client thread is immediately
aborted. But the signal is lost.
If you remove the if (!killed) before boum(-1); you see, that the
pthread_kill from the thread doesn't arrive in the main thread either.


_______________________________________________
pthreads-devel mailing list
[email protected]
http://www-124.ibm.com/developerworks/oss/mailman/listinfo/pthreads-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.