On Tue, Nov 26, 2002 at 05:52:52PM +0100, Michal 'hramrach' Suchanek wrote: > Attaching a simple error printing program that segfaults > for me. And a simple fix to libpthread that makes it not segfault. But I'm not sure the fix implements exactly the right thing. But it makes initial thread locale the global locale which is described as the default behavior in the libc manual.
-- Michal Suchanek [EMAIL PROTECTED]
diff -urN -x CVS libpthread.org/pthread/pt-create.c libpthread/pthread/pt-create.c --- libpthread.org/pthread/pt-create.c 2002-11-19 17:14:58.000000000 +0100 +++ libpthread/pthread/pt-create.c 2002-11-26 18:15:03.000000000 +0100 @@ -21,6 +21,7 @@ #include <errno.h> #include <pthread.h> #include <signal.h> +#include <locale.h> #include <bits/atomic.h> @@ -36,6 +37,7 @@ static void entry_point (void *(*start_routine)(void *), void *arg) { + assert (uselocale (LC_GLOBAL_LOCALE) == 0); pthread_exit (start_routine (arg)); } diff -urN -x CVS libpthread.org/tests/Makefile libpthread/tests/Makefile --- libpthread.org/tests/Makefile 2002-11-19 17:15:35.000000000 +0100 +++ libpthread/tests/Makefile 2002-11-26 18:25:42.000000000 +0100 @@ -2,9 +2,9 @@ LDLIBS = -lpthread -CHECK_SRC := test-1.c test-2.c test-3.c test-6.c test-7.c test-8.c \ - test-9.c test-10.c test-11.c test-12.c test-13.c test-14.c \ - test-15.c test-16.c +CHECK_SRC := test-0.c test-1.c test-2.c test-3.c test-6.c test-7.c \ + test-8.c test-9.c test-10.c test-11.c test-12.c test-13.c \ + test-14.c test-15.c test-16.c CHECK_OBJS := $(addsuffix .o,$(basename $(notdir $(CHECK_SRC)))) CHECK_PROGS := $(basename $(notdir $(CHECK_SRC))) \ @@ -26,4 +26,4 @@ clean: rm -f $(CHECK_OBJS) $(CHECK_PROGS) \ - $(addsuffix .out,$(basename $(notdir $(CHECK_PROGS)))) \ No newline at end of file + $(addsuffix .out,$(basename $(notdir $(CHECK_PROGS)))) diff -urN -x CVS libpthread.org/tests/test-0.c libpthread/tests/test-0.c --- libpthread.org/tests/test-0.c 1970-01-01 01:00:00.000000000 +0100 +++ libpthread/tests/test-0.c 2002-11-26 19:12:27.000000000 +0100 @@ -0,0 +1,54 @@ +#define _GNU_SOURCE + +#include <pthread.h> +#include <unistd.h> +#include <error.h> +#include <errno.h> +#include <stdio.h> + +#define THREADS 500 + + +void * +foo (void *arg) +{ + error (0, EGREGIOUS, "Message foo"); + error (0, EGREGIOUS, "Int1 %i Int2 %i", 1, 2); + return NULL; +} + +int +main (int argc, char **argv) +{ + error_t err; + pthread_t tid; + void * ret; + + fprintf (stderr, "\n\n ***This should print a bunch of error messages.\n\n"); + + error (0, EGREGIOUS, "Message start"); + error (0, EGREGIOUS, "Int1 %i Int2 %i", 1, 2); + + error (0, EGREGIOUS, "Message init"); + error (0, EGREGIOUS, "Int1 %i Int2 %i", 1, 2); + + err = pthread_create (&tid, NULL, foo, NULL); + if (err) + error (0, errno, "pthread_create"); + error (0, EGREGIOUS, "Message create"); + error (0, EGREGIOUS, "Int1 %i Int2 %i", 1, 2); + + sched_yield(); + error (0, EGREGIOUS, "Message yield"); + error (0, EGREGIOUS, "Int1 %i Int2 %i", 1, 2); + + err = pthread_join (tid, &ret); + if (err) + error (0, errno, "pthread_join"); + error (0, EGREGIOUS, "Message join"); + error (0, EGREGIOUS, "Int1 %i Int2 %i", 1, 2); + if ((int)ret) + error (0, EGREGIOUS, "Main: Thread return value %i should be 0", (int)ret); + + return 0; +}