Bug #8369 cluster restart -n fails compiled with linux threads
Submitted: 8 Feb 2005 14:32 Modified: 10 Feb 2005 13:21
Reporter: Tomas Ulin Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Cluster: Cluster (NDB) storage engine Severity:S3 (Non-critical)
Version:4.1 5.0 OS:FreeBSD (freebsd with linux threads)
Assigned to: Assigned Account CPU Architecture:Any

[8 Feb 2005 14:32] Tomas Ulin
Description:
perform
ndb_mgm> all restart -n

How to repeat:
perform
ndb_mgm> all restart -n

Suggested fix:
current compile setup for building mysql results in wrong exitcodes returned to parentprocess through waitpid()

got the following responce on the freebsd mailing list

> 
>> Hi,
>> 
>> the program below (tmp.c)  gives strange output regarding the child exit 
>> status when using linux threads on freebsd 4.7.
>> 
>> With lib pthread- correct:
>> Exit value 123
>> Exit value 123
>> 
>> With llthread - error:
>> Exit value 123
>> Exit value 0
>> 
>> Any ideas?

exit handling is known to be broken in the linuxthreads port, e.g. if one
thread calls exit while other threads are still running then atexit handlers
registered after the one registered by pthread_initialize() are called, and
data structures might be removed while still being used by other threads.

atexit handlers registered before the one registered by pthread_initialize()
might not be called at all, since if other threads were killed while holding
mutexes then the program would just hang.  The exit code is not available for
functions registered with atexit(), so terminating early with the exit code
passed to exit is not easily done.

Additionally, the command "gcc -o tmp tmp.c -L/usr/local/lib -llthread" is
wrong unless you've compiled the linuxthread port with support for emulating
the ABI for native threads (LINUXTHREADS_WRAP_API=yes).  You need to specify
where to find the corresponding header files,
i.e. "-I/usr/local/include/pthread/linuxthreads" has to be added to the
command.

If you compile the linuxthreads port with LINUXTHREADS_DETECT_UNSAFE_EXIT=yes
then your sample program seems to exit with the correct exit code.  But that
has other side effects, e.g. when it was implicit in version 2.2.3_9 of the
linuxthreads port, people reported that /usr/local/bin/mysql_install_db checked
the exit code of mysqld and aborted.

- Tor Egge
[10 Feb 2005 11:28] Tomas Ulin
linux threads is too broken to bother porting cluster to it.

We will not build with linux threads
[10 Feb 2005 12:32] Tomas Ulin
I apologize for the comment above.
[10 Feb 2005 13:21] Tomas Ulin
unfortunately we can't get ndb to work on FreeBSD with linuxthreads until the problem shown in the example program is fixed.

when this issue is resolved, we will try again.

/*
  To test the program, do:

  gcc -I/usr/local/include/pthread/linuxthreads -o tmp tmp.c -L/usr/local/lib -llthread ; ./tmp

If it works, it should end with:
Exit value 123,  should be 123

For us the result is:

Exit value 123,  should be 123
thread: exit
child: exit
Exit value 0,  should be 123

We know that this program works if we do:

gcc -o tmp tmp.c -L/usr/local/lib -pthread ; ./tmp

But this doesn't solve the problem of using NDB with linuxthreads
*/

/*

#define LINUXTHREADS_WRAP_API yes

This program may work with linuxthreads compiled with:
#define LINUXTHREADS_DETECT_UNSAFE_EXIT
but for our purposes this have to work with any installed linux threads
library
*/

#include <pthread.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <stdio.h>

void wait_and_display(pid_t pid)
{
 int status;
 while ( pid != waitpid(pid, &status, 0) );
 printf("Exit value %d,  should be 123\n",  WEXITSTATUS(status));
}
void *athread(void *data)
{
  printf("thread: exit\n");
  pthread_exit(0);
}
int main(void)
{
 pid_t pid;
/* Case 1: Explicit call to exit */
 if ((pid = fork()) == 0) /* child */
   exit(123);
/* parent */
 wait_and_display(pid);
/* Case 2: Start thread and Explicit call to exit */
 if ((pid = fork()) == 0) /* child */
 {
   pthread_t thread;
   pthread_attr_t thread_attr;
   int result;
   pthread_attr_init(&thread_attr);
   result = pthread_create(&thread,
                         &thread_attr,
                         athread,
                         0);

   sleep(2);
   printf("child: exit\n");
   exit(123);
 }
/* parent */
 wait_and_display(pid);
 exit(0);
}
[13 Mar 2014 13:33] Omer Barnir
This bug is not scheduled to be fixed at this time.