Subject: lib/20256: sem_wait in libpthread fails in single-threaded mode
To: None <gnats-bugs@gnats.netbsd.org>
From: Anthony Mallet <anthony.mallet@useless-ficus.net>
List: netbsd-bugs
Date: 02/08/2003 21:40:21
>Number: 20256
>Category: lib
>Synopsis: sem_wait in libpthread fails in single-threaded mode
>Confidential: no
>Severity: serious
>Priority: low
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Feb 08 12:41:00 PST 2003
>Closed-Date:
>Last-Modified:
>Originator: Anthony Mallet
>Release: NetBSD 1.6N
>Organization:
>Environment:
System: NetBSD ficus 1.6N NetBSD 1.6N (FICUS) #0: Sun Feb 2 17:53:57 CET 2003 troot@ficus:/home/build/netbsd-obj-current/sys/arch/i386/compile/FICUS i386
Architecture: i386
Machine: i386
>Description:
sem_wait from libpthread triggers an assert in single-threaded mode:
assertion "next != 0" failed: file
"/home/src/netbsd-current/lib/libpthread/pthread_run.c", line 118,
function "pthread__next"
This PR follows up on the discussion that took place in PR#20001.
>How-To-Repeat:
Compile and run the following:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <pthread.h>
#include <semaphore.h>
#include <sys/types.h>
#include <sys/time.h>
sem_t sem;
void timer_func(int);
int
main(int argc, char *argv[])
{
pthread_t thread;
struct itimerval tv;
int status;
status = sem_init(&sem, 0, 0);
if (status) { perror("sem_init"); return 2; }
/* prepare for receiving SIGALRM */
signal(SIGALRM, timer_func);
/* setup a timer that starts after 1s */
tv.it_interval.tv_usec = 0;
tv.it_interval.tv_sec = 0;
tv.it_value.tv_usec = 0;
tv.it_value.tv_sec = 1;
status = setitimer(ITIMER_REAL, &tv, NULL);
if (status) { perror("setitimer"); return 2; }
/* block on the semaphore */
printf("before sem_wait\n");
sem_wait(&sem);
printf("after sem_wait\n");
return 0;
}
/* SIGALRM handler */
void
timer_func(int dummy)
{
printf("before sem_post\n");
sem_post(&sem);
printf("after sem_post\n");
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: