NetBSD Problem Report #52386

From www@NetBSD.org  Sun Jul  9 15:29:55 2017
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 360227A276
	for <gnats-bugs@gnats.NetBSD.org>; Sun,  9 Jul 2017 15:29:55 +0000 (UTC)
Message-Id: <20170709152954.1352C7A2A6@mollari.NetBSD.org>
Date: Sun,  9 Jul 2017 15:29:54 +0000 (UTC)
From: n54@gmx.com
Reply-To: n54@gmx.com
To: gnats-bugs@NetBSD.org
Subject: pthread(3) doesn't respect PTHREAD_DESTRUCTOR_ITERATIONS
X-Send-Pr-Version: www-1.0

>Number:         52386
>Category:       lib
>Synopsis:       pthread(3) doesn't respect PTHREAD_DESTRUCTOR_ITERATIONS
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jul 09 15:30:00 +0000 2017
>Closed-Date:    Sun Jul 09 23:45:00 +0000 2017
>Last-Modified:  Mon Jul 24 05:50:01 +0000 2017
>Originator:     Kamil Rytarowski
>Release:        NetBSD 8.99.1 amd64
>Organization:
TNF
>Environment:
NetBSD chieftec 8.99.1 NetBSD 8.99.1 (GENERIC) #5: Sat Jul  1 17:48:34 CEST 2017  root@chieftec:/public/netbsd-root/sys/arch/amd64/compile/GENERIC amd64
>Description:
PTHREAD_DESTRUCTOR_ITERATIONS is not respected as the maximum number of destructor iterations.

This has been caught by LLVM sanitizer tests. This breaks two tests.

compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cc

    SanitizerCommon-Unit :: ./Sanitizer-i386-Test/SanitizerCommon.PthreadDestructorIterations
    SanitizerCommon-Unit :: ./Sanitizer-x86_64-Test/SanitizerCommon.PthreadDestructorIterations
>How-To-Repeat:
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <pthread.h>
#include <limits.h>

static pthread_key_t key;
static bool destructor_executed;

void
destructor(void *arg)
{
  uintptr_t iter = (uintptr_t)arg;
  if (iter > 1) {
    assert(0 == pthread_setspecific(key, (void*)(uintptr_t)(iter - 1)));
    return;
  }
  destructor_executed = true;
}

void *
thread_func(void *arg)
{
  return (void*)(uintptr_t)pthread_setspecific(key, arg);
}

static void
SpawnThread(int iteration)
{
  destructor_executed = false;
  pthread_t tid;
  assert(0 == pthread_create(&tid, 0, thread_func, (void *)(uintptr_t)(iteration)));
  void *retval;               
  assert(0 == pthread_join(tid, &retval));
  assert(0 == retval);
}


int
main(int argc, char **argv)
{
	pthread_key_create(&key, destructor);
	SpawnThread(PTHREAD_DESTRUCTOR_ITERATIONS);
	assert(destructor_executed == true);
	SpawnThread(PTHREAD_DESTRUCTOR_ITERATIONS + 1);
	assert(destructor_executed == false);
	assert(0 == pthread_key_delete(key));

	return 0;
}

>Fix:
N/A

>Release-Note:

>Audit-Trail:
From: Joerg Sonnenberger <joerg@bec.de>
To: gnats-bugs@NetBSD.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org
Subject: Re: lib/52386: pthread(3) doesn't respect
 PTHREAD_DESTRUCTOR_ITERATIONS
Date: Sun, 9 Jul 2017 19:19:07 +0200

 On Sun, Jul 09, 2017 at 03:30:00PM +0000, n54@gmx.com wrote:
 > PTHREAD_DESTRUCTOR_ITERATIONS is not respected as the maximum number of destructor iterations.

 The test case is incorrect. PTHREAD_DESTRUCTOR_ITERATIONS specifies a
 lower limit on the number of iterations performed. It is explicitly not
 a hard limit. To quote POSIX:

 Calling pthread_setspecific() from a thread-specific data destructor
 routine may result either in lost storage (after at least
 PTHREAD_DESTRUCTOR_ITERATIONS attempts at destruction) or in an infinite
 loop.

 Joerg

From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, lib-bug-people@netbsd.org, 
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, n54@gmx.com
Cc: 
Subject: Re: lib/52386: pthread(3) doesn't respect PTHREAD_DESTRUCTOR_ITERATIONS
Date: Sun, 9 Jul 2017 16:20:39 -0400

 On Jul 9,  5:20pm, joerg@bec.de (Joerg Sonnenberger) wrote:
 -- Subject: Re: lib/52386: pthread(3) doesn't respect PTHREAD_DESTRUCTOR_ITER

 |  On Sun, Jul 09, 2017 at 03:30:00PM +0000, n54@gmx.com wrote:
 |  > PTHREAD_DESTRUCTOR_ITERATIONS is not respected as the maximum number of destructor iterations.
 |  
 |  The test case is incorrect. PTHREAD_DESTRUCTOR_ITERATIONS specifies a
 |  lower limit on the number of iterations performed. It is explicitly not
 |  a hard limit. To quote POSIX:
 |  
 |  Calling pthread_setspecific() from a thread-specific data destructor
 |  routine may result either in lost storage (after at least
 |  PTHREAD_DESTRUCTOR_ITERATIONS attempts at destruction) or in an infinite
 |  loop.

 I agree, but making the code using the iteration constant we advertise
 is simple enough.

 christos

From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52386 CVS commit: src/lib/libpthread
Date: Sun, 9 Jul 2017 16:21:08 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Sun Jul  9 20:21:08 UTC 2017

 Modified Files:
 	src/lib/libpthread: pthread_tsd.c

 Log Message:
 PR/52386: Use the number of iterations we document.


 To generate a diff of this commit:
 cvs rdiff -u -r1.15 -r1.16 src/lib/libpthread/pthread_tsd.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: kamil@NetBSD.org
State-Changed-When: Mon, 10 Jul 2017 01:45:00 +0200
State-Changed-Why:
Fixed by Christos.
LLVM compiler-rt sanitizer common tests (check-sanitizer) works now.


From: "Soren Jacobsen" <snj@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52386 CVS commit: [netbsd-8] src/lib/libpthread
Date: Mon, 24 Jul 2017 05:48:00 +0000

 Module Name:	src
 Committed By:	snj
 Date:		Mon Jul 24 05:48:00 UTC 2017

 Modified Files:
 	src/lib/libpthread [netbsd-8]: pthread_tsd.c

 Log Message:
 Pull up following revision(s) (requested by kamil in ticket #119):
 	lib/libpthread/pthread_tsd.c: revision 1.16
 PR/52386: Use the number of iterations we document.


 To generate a diff of this commit:
 cvs rdiff -u -r1.15 -r1.15.8.1 src/lib/libpthread/pthread_tsd.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.