From owner-freebsd-threads@FreeBSD.ORG Wed Jan 26 00:50:08 2005 Return-Path: Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 013A616A4CF for ; Wed, 26 Jan 2005 00:50:08 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id AFF5743D58 for ; Wed, 26 Jan 2005 00:50:07 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.1/8.13.1) with ESMTP id j0Q0o7M3037193 for ; Wed, 26 Jan 2005 00:50:07 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.1/8.13.1/Submit) id j0Q0o708037187; Wed, 26 Jan 2005 00:50:07 GMT (envelope-from gnats) Resent-Date: Wed, 26 Jan 2005 00:50:07 GMT Resent-Message-Id: <200501260050.j0Q0o708037187@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-threads@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Serguei Leontiev Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DBAD816A4CE for ; Wed, 26 Jan 2005 00:48:25 +0000 (GMT) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id A760743D3F for ; Wed, 26 Jan 2005 00:48:25 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j0Q0mP8V083525 for ; Wed, 26 Jan 2005 00:48:25 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id j0Q0mPpd083524; Wed, 26 Jan 2005 00:48:25 GMT (envelope-from nobody) Message-Id: <200501260048.j0Q0mPpd083524@www.freebsd.org> Date: Wed, 26 Jan 2005 00:48:25 GMT From: Serguei Leontiev To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Subject: threads/76690: fork hang in child for (-lc_r & -lthr) X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jan 2005 00:50:08 -0000 >Number: 76690 >Category: threads >Synopsis: fork hang in child for (-lc_r & -lthr) >Confidential: no >Severity: critical >Priority: medium >Responsible: freebsd-threads >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Jan 26 00:50:07 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Serguei Leontiev >Release: 5.2.1 >Organization: Crypto-Pro >Environment: FreeBSD build-fbsd 5.2.1-RELEASE FreeBSD 5.2.1-RELEASE #0: Mon Feb 23 20:45:55 GMT 2004 root@wv1u.btc.adaptec.com:/usr/obj/usr/src/sys/GENERIC i386 >Description: For multithreaded application malloc/free in other thread cause fork() hang in child process. Child process does not anything to work or threading operations. This bug first detected for system() library function in multithreaded application. This bug affected "-lc_r" and "-lthr" library. Library "-lkse" seems OK. Sorry for my bests English. >How-To-Repeat: #include #include #include #include #include #include #include const int INFL = 1000000000; const int PTHR = 4; const int NATR = 2; #ifndef SEMI_OK // if SEMI_OK not defined - >95% hang on my system const int FRKL = 100; #else // if SEMI_OK defined - 50% hang on my system const int FRKL = 3; #endif void *malloc_free(void *pvcnt) { volatile sig_atomic_t *pscnt = (volatile sig_atomic_t *)pvcnt; int n = *pscnt; int i; void *m; for(i = 0; i < n; i++){ m = malloc(10); *pscnt = i; free(m); } return NULL; } int main (void) { pthread_attr_t attrs[NATR]; pthread_t thread_id; volatile sig_atomic_t cnt[PTHR]; int i; pid_t pid, savedpid; int pstat; pthread_attr_init(&attrs[0]); pthread_attr_setdetachstate(&attrs[0], PTHREAD_CREATE_DETACHED); pthread_attr_setscope(&attrs[0], PTHREAD_SCOPE_PROCESS); pthread_attr_init(&attrs[1]); pthread_attr_setdetachstate(&attrs[1], PTHREAD_CREATE_DETACHED); pthread_attr_setscope(&attrs[1], PTHREAD_SCOPE_SYSTEM); for(i = 0; i < PTHR; i++) { cnt[i] = INFL; if(pthread_create(&thread_id, &attrs[i%NATR], &malloc_free, (void *)&cnt[i])){ perror("pthread_create:"); return 1; } } fprintf(stderr, "Threads created.\n"); for (i = 0; i < FRKL; i++) { fprintf(stderr, "forking\n"); switch(pid = fork()) { case -1: /* error */ perror("fork fail:"); return 2; case 0: /* child */ // Child don't anything to work - simple exit // When child hang, this hang in fork code _exit(0); default: /* parent */ savedpid = pid; do{ pid = waitpid(savedpid, &pstat, 0); }while(pid == -1 && errno == EINTR); break; } } fprintf(stderr, "Threads OK:"); for(i = 0; i < PTHR; i++){ fprintf(stderr, " %d", (int)cnt[i]); } fprintf(stderr, "\n"); _exit(0); return 0; } >Fix: >Release-Note: >Audit-Trail: >Unformatted: