Fix the comparision function used by the red-black tree global thread list

implementation:
-don't return a difference, this can overflow
-don't try to substract typed pointers which don't belong to the
 same object, this gives undefined results

This fixes instabilities of programs which use more than a handful
of threads, eg spuriously failing pthread_join().
This commit is contained in:
drochner 2009-04-01 10:13:24 +00:00
parent 3a9e7e68ee
commit f1c955a1b2
1 changed files with 9 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: pthread.c,v 1.108 2009/03/30 21:32:51 ad Exp $ */
/* $NetBSD: pthread.c,v 1.109 2009/04/01 10:13:24 drochner Exp $ */
/*-
* Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pthread.c,v 1.108 2009/03/30 21:32:51 ad Exp $");
__RCSID("$NetBSD: pthread.c,v 1.109 2009/04/01 10:13:24 drochner Exp $");
#define __EXPOSE_STACK 1
@ -1275,7 +1275,13 @@ pthread__stackid_setup(void *base, size_t size, pthread_t *tp)
static int
pthread__cmp(struct __pthread_st *a, struct __pthread_st *b)
{
return b - a;
if ((uintptr_t)a < (uintptr_t)b)
return (-1);
else if (a == b)
return 0;
else
return 1;
}
RB_GENERATE_STATIC(__pthread__alltree, __pthread_st, pt_alltree, pthread__cmp)
#endif