From ea6390b2f20a03b7d504bc68a1c95e645d271149 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Wed, 2 Nov 2011 17:38:46 +0100 Subject: Remove all the values when deleting a key When deleting a key using `pthread_key_delete', delete all the values associated to that key in all the threads available. Otherwise, the key reuse in `pthread_key_create' can cause new keys to have thread specific data of the previously used key with the same index. Add a test for this case, which creates and deletes pairs of keys checking that they have a NULL thread specific data after creation. * sysdeps/hurd/pt-key-delete.c (pthread_key_delete): Remove all the values of the key in all the threads. * tests/Makefile (CHECK_SRC): Add test-17.c. * tests/test-17.c: New file. --- tests/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Makefile') diff --git a/tests/Makefile b/tests/Makefile index 9509c95..4e2a4a8 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -4,7 +4,7 @@ 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 + test-15.c test-16.c test-17.c CHECK_OBJS := $(addsuffix .o,$(basename $(notdir $(CHECK_SRC)))) CHECK_PROGS := $(basename $(notdir $(CHECK_SRC))) \ -- cgit v1.2.3 From 76af844177c2bacd7a39e865cf0bbe484a68ddb8 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Sat, 5 Nov 2011 01:16:41 +0100 Subject: Correct logic for PTHREAD_KEY_INVALID slots. * sysdeps/hurd/pt-destroy-specific.c (__pthread_destroy_specific): Correct logic for PTHREAD_KEY_INVALID slots. * tests/test-__pthread_destroy_specific-skip.c: New file. * tests/Makefile (CHECK_SRC): Add test-__pthread_destroy_specific-skip.c. --- sysdeps/hurd/pt-destroy-specific.c | 2 +- tests/Makefile | 2 +- tests/test-__pthread_destroy_specific-skip.c | 83 ++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 tests/test-__pthread_destroy_specific-skip.c (limited to 'tests/Makefile') diff --git a/sysdeps/hurd/pt-destroy-specific.c b/sysdeps/hurd/pt-destroy-specific.c index 23c7fbc..f7896e5 100644 --- a/sysdeps/hurd/pt-destroy-specific.c +++ b/sysdeps/hurd/pt-destroy-specific.c @@ -48,7 +48,7 @@ __pthread_destroy_specific (struct __pthread *thread) void *value; if (__pthread_key_destructors[i] == PTHREAD_KEY_INVALID) - break; + continue; value = hurd_ihash_find (thread->thread_specifics, i); if (value) diff --git a/tests/Makefile b/tests/Makefile index 9509c95..343a644 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -4,7 +4,7 @@ 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 + test-15.c test-16.c test-__pthread_destroy_specific-skip.c CHECK_OBJS := $(addsuffix .o,$(basename $(notdir $(CHECK_SRC)))) CHECK_PROGS := $(basename $(notdir $(CHECK_SRC))) \ diff --git a/tests/test-__pthread_destroy_specific-skip.c b/tests/test-__pthread_destroy_specific-skip.c new file mode 100644 index 0000000..b2c4c0b --- /dev/null +++ b/tests/test-__pthread_destroy_specific-skip.c @@ -0,0 +1,83 @@ +/* Check that __pthread_destroy_specific works correctly if it has to skip + unused slots. */ + +#define _GNU_SOURCE + +#include +#include +#include + + +#define N_k 42 + +static volatile int v; + +static void +d (void *x) +{ + int *i = (int *) x; + + if (v != *i) + error (1, 0, "FAILED %d %d", v, *i); + v += 2; + + printf ("%s %d\n", __FUNCTION__, *i); + fflush (stdout); +} + +static void * +test (void *x) +{ + pthread_key_t k[N_k]; + static int k_v[N_k]; + + int err, i; + + for (i = 0; i < N_k; i += 1) + { + err = pthread_key_create (&k[i], &d); + if (err != 0) + error (1, err, "pthread_key_create %d", i); + } + + for (i = 0; i < N_k; i += 1) + { + k_v[i] = i; + err = pthread_setspecific (k[i], &k_v[i]); + if (err != 0) + error (1, err, "pthread_setspecific %d", i); + } + + /* Delete every even key. */ + for (i = 0; i < N_k; i += 2) + { + err = pthread_key_delete (k[i]); + if (err != 0) + error (1, err, "pthread_key_delete %d", i); + } + + v = 1; + pthread_exit (NULL); + + return NULL; +} + + +int main(void) +{ + pthread_t tid; + int err; + + err = pthread_create (&tid, 0, test, NULL); + if (err != 0) + error (1, err, "pthread_create"); + + err = pthread_join(tid, NULL); + if (err) + error (1, err, "pthread_join"); + + if (v != N_k + 1) + error (1, 0, "FAILED END %d %d", v, N_k + 1); + + return 0; +} -- cgit v1.2.3 From 640cfa0a4af3dc399bff496fd94081a99dbbcdd2 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Tue, 7 Aug 2012 23:04:43 +0200 Subject: tests/Makefile: Support INSTALL_ROOT environment variable. * tests/Makefile [ifdef INSTALL_ROOT] (INSTALL_ROOT_CPPFLAGS) (INSTALL_ROOT_LDFLAGS): New variables. (%.o: %.c, %: %.o): New rules. (%-static: %.o): Update rule. * tests/README: Update. --- tests/Makefile | 13 ++++++++++++- tests/README | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/README (limited to 'tests/Makefile') diff --git a/tests/Makefile b/tests/Makefile index 5ebc01d..7177ad1 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,3 +1,8 @@ +ifdef INSTALL_ROOT +INSTALL_ROOT_CPPFLAGS = -isystem $(INSTALL_ROOT)/include +INSTALL_ROOT_LDFLAGS = -L$(INSTALL_ROOT)/lib -Wl,-rpath,$(INSTALL_ROOT)/lib +endif + CFLAGS=-Wall -g LDLIBS = -lpthread @@ -10,8 +15,14 @@ CHECK_OBJS := $(addsuffix .o,$(basename $(notdir $(CHECK_SRC)))) CHECK_PROGS := $(basename $(notdir $(CHECK_SRC))) \ $(addsuffix -static, $(basename $(CHECK_SRC))) +%.o: %.c + $(CC) $(INSTALL_ROOT_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) $< -c -o $@ + +%: %.o + $(CC) $(INSTALL_ROOT_LDFLAGS) $(LDFLAGS) $< -o $@ $(LDLIBS) + %-static: %.o - $(CC) -static $(CFLAGS) $(LDFLAGS) $< -o $@ $(LDLIBS) + $(CC) -static $(INSTALL_ROOT_LDFLAGS) $(LDFLAGS) $< -o $@ $(LDLIBS) check: $(CHECK_OBJS) $(CHECK_PROGS) for i in $(CHECK_PROGS); do \ diff --git a/tests/README b/tests/README new file mode 100644 index 0000000..230f1b2 --- /dev/null +++ b/tests/README @@ -0,0 +1,6 @@ +Testing of installed package: + + $ [libpthread]/configure --prefix=[install_root] + $ make + $ make install + $ make -C [libpthread]/tests/ INSTALL_ROOT=[install_root] clean check -- cgit v1.2.3