The libpthread tests have been converted to atf; remove the old versions.
This commit is contained in:
parent
b0efb6eb58
commit
59c643ac55
@ -1,8 +1,8 @@
|
||||
# $NetBSD: Makefile,v 1.23 2010/07/16 13:59:07 jmmv Exp $
|
||||
# $NetBSD: Makefile,v 1.24 2010/07/16 15:46:01 jmmv Exp $
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
SUBDIR+= csu libc libm libpthread
|
||||
SUBDIR+= csu libc libm
|
||||
|
||||
.if (${MACHINE_CPU} != "alpha" && \
|
||||
${MACHINE_CPU} != "mips" && \
|
||||
|
@ -1,38 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.32 2009/04/02 12:58:44 drochner Exp $
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
.if exists(${.CURDIR}/../../../lib/libpthread/arch/${MACHINE_ARCH})
|
||||
ARCHSUBDIR= ${MACHINE_ARCH}
|
||||
.elif exists(${.CURDIR}/../../../lib/libpthread/arch/${MACHINE_CPU})
|
||||
ARCHSUBDIR= ${MACHINE_CPU}
|
||||
.else
|
||||
.BEGIN:
|
||||
@echo "WARNING: no ARCHSUBDIR for ${MACHINE_ARCH}/${MACHINE_CPU}"
|
||||
@echo "*** REFUSING TO CONTINUE! (nag, nag, nag) ***"
|
||||
@false # this is intentional!
|
||||
.endif
|
||||
|
||||
.if defined(ARCHSUBDIR)
|
||||
|
||||
SUBDIR+= atexit \
|
||||
barrier1 \
|
||||
cancel2 \
|
||||
cond1 cond2 cond3 cond4 cond5 cond6 condcancel1 \
|
||||
exit1 \
|
||||
find \
|
||||
fork \
|
||||
fpu \
|
||||
kill1 \
|
||||
mutex1 mutex2 mutex3 mutex4 \
|
||||
name \
|
||||
once1 once2 once3 \
|
||||
preempt1 \
|
||||
resolv rwlock1 \
|
||||
sem sem2 sigalarm sigmask1 sigmask2 sigmask3 sigmask4 \
|
||||
siglongjmp1 sigsuspend \
|
||||
sleep1
|
||||
|
||||
.endif
|
||||
|
||||
.include <bsd.subdir.mk>
|
@ -1,25 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/03/04 18:00:49 thorpej Exp $
|
||||
|
||||
NOMAN= # defined
|
||||
|
||||
PROG= atexit
|
||||
|
||||
ATEXITDIR= ${.CURDIR}/../../libc/atexit
|
||||
.PATH: ${ATEXITDIR}
|
||||
|
||||
# Note: this test relies on being dynamically linked. You will get a
|
||||
# spurious PASS for a statically linked test.
|
||||
DPADD+= ${LIBPTHREAD}
|
||||
LDADD+= -lpthread
|
||||
|
||||
CLEANFILES+= output
|
||||
|
||||
regress: ${PROG}
|
||||
./${PROG} > output
|
||||
if cmp ${ATEXITDIR}/expected output; then \
|
||||
echo PASSED; \
|
||||
else \
|
||||
echo FAILED; exit 1; \
|
||||
fi
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/01/30 18:23:09 thorpej Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= barrier1
|
||||
SRCS= barrier1.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./barrier1
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,78 +0,0 @@
|
||||
/* $NetBSD: barrier1.c,v 1.3 2007/12/03 17:59:45 ad Exp $ */
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void *threadfunc(void *arg);
|
||||
|
||||
pthread_barrier_t barrier;
|
||||
pthread_mutex_t mutex;
|
||||
int serial_count;
|
||||
int after_barrier_count;
|
||||
|
||||
#define COUNT 10
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i, ret;
|
||||
pthread_t new[COUNT];
|
||||
void *joinval;
|
||||
|
||||
pthread_mutex_init(&mutex, NULL);
|
||||
|
||||
ret = pthread_barrier_init(&barrier, NULL, COUNT);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_barrier_init");
|
||||
|
||||
for (i = 0; i < COUNT; i++) {
|
||||
pthread_mutex_lock(&mutex);
|
||||
assert(after_barrier_count == 0);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
ret = pthread_create(&new[i], NULL, threadfunc,
|
||||
(void *)(long)i);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_create");
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
for (i = 0; i < COUNT; i++) {
|
||||
ret = pthread_join(new[i], &joinval);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_join: %d", ret);
|
||||
pthread_mutex_lock(&mutex);
|
||||
assert(after_barrier_count > i);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
printf("main joined with thread %d\n", i);
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
assert(after_barrier_count == COUNT);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
assert(serial_count == 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
threadfunc(void *arg)
|
||||
{
|
||||
int which = (int)(long)arg;
|
||||
int ret;
|
||||
|
||||
printf("thread %d entering barrier\n", which);
|
||||
ret = pthread_barrier_wait(&barrier);
|
||||
printf("thread %d leaving barrier -> %d\n", which, ret);
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
after_barrier_count++;
|
||||
if (ret == PTHREAD_BARRIER_SERIAL_THREAD)
|
||||
serial_count++;
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
return NULL;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/07/22 21:26:13 nathanw Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= cancel2
|
||||
SRCS= cancel2.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./cancel2
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,27 +0,0 @@
|
||||
/* $NetBSD: cancel2.c,v 1.3 2004/03/05 15:07:22 wiz Exp $ */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
char str1[] = "You should see this.\n";
|
||||
char str2[] = "You should not see this.\n";
|
||||
|
||||
printf("Cancellation test 2: Self-cancellation and disabling.\n");
|
||||
|
||||
|
||||
pthread_cancel(pthread_self());
|
||||
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
|
||||
|
||||
write(STDOUT_FILENO, str1, sizeof(str1));
|
||||
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
|
||||
write(STDOUT_FILENO, str2, sizeof(str2));
|
||||
|
||||
exit(1);
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/01/30 18:53:45 thorpej Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= cond1
|
||||
SRCS= cond1.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./cond1
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,74 +0,0 @@
|
||||
/* $NetBSD: cond1.c,v 1.1 2003/01/30 18:53:46 thorpej Exp $ */
|
||||
|
||||
#include <err.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void *threadfunc(void *arg);
|
||||
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int x,ret;
|
||||
pthread_t new;
|
||||
void *joinval;
|
||||
int sharedval;
|
||||
|
||||
printf("1: condition variable test 1\n");
|
||||
|
||||
pthread_mutex_init(&mutex, NULL);
|
||||
pthread_cond_init(&cond, NULL);
|
||||
|
||||
x = 20;
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
sharedval = 1;
|
||||
|
||||
ret = pthread_create(&new, NULL, threadfunc, &sharedval);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_create");
|
||||
|
||||
printf("1: Before waiting.\n");
|
||||
do {
|
||||
sleep(2);
|
||||
pthread_cond_wait(&cond, &mutex);
|
||||
printf("1: After waiting, in loop.\n");
|
||||
} while (sharedval != 0);
|
||||
|
||||
printf("1: After the loop.\n");
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
printf("1: After releasing the mutex.\n");
|
||||
ret = pthread_join(new, &joinval);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_join");
|
||||
|
||||
printf("1: Thread joined.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
threadfunc(void *arg)
|
||||
{
|
||||
int *share = (int *) arg;
|
||||
|
||||
printf("2: Second thread.\n");
|
||||
|
||||
printf("2: Locking mutex\n");
|
||||
pthread_mutex_lock(&mutex);
|
||||
printf("2: Got mutex.\n");
|
||||
printf("Shared value: %d. Changing to 0.\n", *share);
|
||||
*share = 0;
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
pthread_cond_signal(&cond);
|
||||
|
||||
return NULL;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/01/30 18:53:46 thorpej Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= cond2
|
||||
SRCS= cond2.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./cond2
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,75 +0,0 @@
|
||||
/* $NetBSD: cond2.c,v 1.1 2003/01/30 18:53:46 thorpej Exp $ */
|
||||
|
||||
#include <err.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void *threadfunc(void *arg);
|
||||
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int x,ret;
|
||||
pthread_t new;
|
||||
void *joinval;
|
||||
int sharedval;
|
||||
|
||||
printf("1: condition variable test 2\n");
|
||||
|
||||
pthread_mutex_init(&mutex, NULL);
|
||||
pthread_cond_init(&cond, NULL);
|
||||
|
||||
x = 20;
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
sharedval = 1;
|
||||
|
||||
ret = pthread_create(&new, NULL, threadfunc, &sharedval);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_create");
|
||||
|
||||
printf("1: Before waiting.\n");
|
||||
do {
|
||||
sleep(2);
|
||||
pthread_cond_wait(&cond, &mutex);
|
||||
printf("1: After waiting, in loop.\n");
|
||||
} while (sharedval != 0);
|
||||
|
||||
printf("1: After the loop.\n");
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
printf("1: After releasing the mutex.\n");
|
||||
ret = pthread_join(new, &joinval);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_join");
|
||||
|
||||
printf("1: Thread joined.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
threadfunc(void *arg)
|
||||
{
|
||||
int *share = (int *) arg;
|
||||
|
||||
printf("2: Second thread.\n");
|
||||
|
||||
printf("2: Locking mutex\n");
|
||||
pthread_mutex_lock(&mutex);
|
||||
printf("2: Got mutex.\n");
|
||||
printf("Shared value: %d. Changing to 0.\n", *share);
|
||||
*share = 0;
|
||||
|
||||
/* Signal first, then unlock, for a different test than #1. */
|
||||
pthread_cond_signal(&cond);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
return NULL;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/01/30 18:53:47 thorpej Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= cond3
|
||||
SRCS= cond3.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./cond3
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,72 +0,0 @@
|
||||
/* $NetBSD: cond3.c,v 1.1 2003/01/30 18:53:47 thorpej Exp $ */
|
||||
|
||||
#include <err.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void *threadfunc(void *arg);
|
||||
|
||||
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int x,ret;
|
||||
pthread_t new;
|
||||
void *joinval;
|
||||
int sharedval;
|
||||
|
||||
printf("1: condition variable test 3\n");
|
||||
|
||||
x = 20;
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
sharedval = 1;
|
||||
|
||||
ret = pthread_create(&new, NULL, threadfunc, &sharedval);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_create");
|
||||
|
||||
printf("1: Before waiting.\n");
|
||||
do {
|
||||
sleep(2);
|
||||
pthread_cond_wait(&cond, &mutex);
|
||||
printf("1: After waiting, in loop.\n");
|
||||
} while (sharedval != 0);
|
||||
|
||||
printf("1: After the loop.\n");
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
printf("1: After releasing the mutex.\n");
|
||||
ret = pthread_join(new, &joinval);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_join");
|
||||
|
||||
printf("1: Thread joined.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
threadfunc(void *arg)
|
||||
{
|
||||
int *share = (int *) arg;
|
||||
|
||||
printf("2: Second thread.\n");
|
||||
|
||||
printf("2: Locking mutex\n");
|
||||
pthread_mutex_lock(&mutex);
|
||||
printf("2: Got mutex.\n");
|
||||
printf("Shared value: %d. Changing to 0.\n", *share);
|
||||
*share = 0;
|
||||
|
||||
/* Signal first, then unlock, for a different test than #1. */
|
||||
pthread_cond_signal(&cond);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
return NULL;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/01/30 18:53:48 thorpej Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= cond4
|
||||
SRCS= cond4.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./cond4
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,93 +0,0 @@
|
||||
/* $NetBSD: cond4.c,v 1.2 2007/01/20 19:21:18 christos Exp $ */
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void *threadfunc(void *arg);
|
||||
|
||||
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
|
||||
int count, total, toggle;
|
||||
#define COUNT 50000
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int ret;
|
||||
pthread_t new;
|
||||
void *joinval;
|
||||
int sharedval;
|
||||
|
||||
printf("1: condition variable test 4\n");
|
||||
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
if (ret)
|
||||
err(1, "pthread_mutex_lock(1)");
|
||||
|
||||
count = COUNT;
|
||||
toggle = 0;
|
||||
|
||||
ret = pthread_create(&new, NULL, threadfunc, &sharedval);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_create");
|
||||
|
||||
printf("1: Before waiting.\n");
|
||||
while (count>0) {
|
||||
count--;
|
||||
total++;
|
||||
toggle = 1;
|
||||
#if 0
|
||||
printf("1: Before signal %d.\n", count);
|
||||
#endif
|
||||
pthread_cond_signal(&cond);
|
||||
do {
|
||||
pthread_cond_wait(&cond, &mutex);
|
||||
} while (toggle != 0);
|
||||
}
|
||||
printf("1: After the loop.\n");
|
||||
|
||||
toggle = 1;
|
||||
pthread_mutex_unlock(&mutex);
|
||||
pthread_cond_signal(&cond);
|
||||
|
||||
printf("1: After releasing the mutex.\n");
|
||||
ret = pthread_join(new, &joinval);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_join");
|
||||
|
||||
printf("1: Thread joined. Final count = %d, total = %d\n",
|
||||
count, total);
|
||||
assert(count == 0);
|
||||
assert(total == COUNT);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *threadfunc(void *arg)
|
||||
{
|
||||
#if 0
|
||||
int *share = (int *) arg;
|
||||
#endif
|
||||
|
||||
printf("2: Second thread.\n");
|
||||
pthread_mutex_lock(&mutex);
|
||||
printf("2: Before the loop.\n");
|
||||
while (count>0) {
|
||||
count--;
|
||||
total++;
|
||||
toggle = 0;
|
||||
#if 0
|
||||
printf("2: Before signal %d.\n", count);
|
||||
#endif
|
||||
pthread_cond_signal(&cond);
|
||||
do {
|
||||
pthread_cond_wait(&cond, &mutex);
|
||||
} while (toggle != 1);
|
||||
}
|
||||
printf("2: After the loop.\n");
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
return NULL;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/01/30 18:57:07 thorpej Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= cond5
|
||||
SRCS= cond5.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./cond5
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,87 +0,0 @@
|
||||
/* $NetBSD: cond5.c,v 1.2 2007/01/20 19:22:29 christos Exp $ */
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void *threadfunc(void *arg);
|
||||
|
||||
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
|
||||
int count, total, toggle;
|
||||
#define COUNT 50000
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_t new;
|
||||
void *joinval;
|
||||
int sharedval;
|
||||
|
||||
printf("1: condition variable test 5\n");
|
||||
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
if (ret)
|
||||
err(1, "pthread_mutex_lock(1)");
|
||||
|
||||
count = COUNT;
|
||||
toggle = 0;
|
||||
|
||||
ret = pthread_create(&new, NULL, threadfunc, &sharedval);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_create");
|
||||
|
||||
printf("1: Before waiting.\n");
|
||||
while (count>0) {
|
||||
count--;
|
||||
total++;
|
||||
toggle = 1;
|
||||
pthread_cond_broadcast(&cond);
|
||||
do {
|
||||
pthread_cond_wait(&cond, &mutex);
|
||||
} while (toggle != 0);
|
||||
}
|
||||
printf("1: After the loop.\n");
|
||||
|
||||
toggle = 1;
|
||||
pthread_mutex_unlock(&mutex);
|
||||
pthread_cond_signal(&cond);
|
||||
|
||||
printf("1: After releasing the mutex.\n");
|
||||
ret = pthread_join(new, &joinval);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_join");
|
||||
|
||||
printf("1: Thread joined. Final count = %d, total = %d\n",
|
||||
count, total);
|
||||
assert(count == 0);
|
||||
assert(total == COUNT);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
threadfunc(void *arg)
|
||||
{
|
||||
#if 0
|
||||
int *share = (int *) arg;
|
||||
#endif
|
||||
|
||||
printf("2: Second thread.\n");
|
||||
pthread_mutex_lock(&mutex);
|
||||
while (count>0) {
|
||||
count--;
|
||||
total++;
|
||||
toggle = 0;
|
||||
pthread_cond_signal(&cond);
|
||||
do {
|
||||
pthread_cond_wait(&cond, &mutex);
|
||||
} while (toggle != 1);
|
||||
}
|
||||
printf("2: After the loop.\n");
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
return NULL;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2004/12/10 17:07:31 nathanw Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= cond6
|
||||
SRCS= cond6.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./cond6
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,93 +0,0 @@
|
||||
/* $NetBSD: cond6.c,v 1.2 2004/12/29 20:34:11 nathanw Exp $ */
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
void *threadfunc(void *arg);
|
||||
|
||||
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int ret;
|
||||
pthread_t new;
|
||||
struct timespec ts;
|
||||
struct timeval tv;
|
||||
|
||||
printf("condition variable test 6: bogus timedwaits\n");
|
||||
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
if (ret)
|
||||
err(1, "pthread_mutex_lock(1)");
|
||||
|
||||
printf("unthreaded test (past)\n");
|
||||
gettimeofday(&tv, NULL);
|
||||
tv.tv_sec -= 2; /* Place the time in the past */
|
||||
TIMEVAL_TO_TIMESPEC(&tv, &ts);
|
||||
|
||||
ret = pthread_cond_timedwait(&cond, &mutex, &ts);
|
||||
if (ret != ETIMEDOUT) {
|
||||
printf("FAIL: pthread_cond_timedwait() (unthreaded)"
|
||||
" in the past returned %d\n", ret);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("unthreaded test (zero time)\n");
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
TIMEVAL_TO_TIMESPEC(&tv, &ts);
|
||||
|
||||
ret = pthread_cond_timedwait(&cond, &mutex, &ts);
|
||||
if (ret != ETIMEDOUT) {
|
||||
printf("FAIL: pthread_cond_timedwait() (unthreaded)"
|
||||
" with zero time returned %d\n", ret);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret = pthread_create(&new, NULL, threadfunc, NULL);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_create");
|
||||
ret = pthread_join(new, NULL);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_join");
|
||||
|
||||
printf("threaded test\n");
|
||||
gettimeofday(&tv, NULL);
|
||||
tv.tv_sec -= 2; /* Place the time in the past */
|
||||
TIMEVAL_TO_TIMESPEC(&tv, &ts);
|
||||
|
||||
ret = pthread_cond_timedwait(&cond, &mutex, &ts);
|
||||
if (ret != ETIMEDOUT) {
|
||||
printf("FAIL: pthread_cond_timedwait() (threaded)"
|
||||
" in the past returned %d\n", ret);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("threaded test (zero time)\n");
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
TIMEVAL_TO_TIMESPEC(&tv, &ts);
|
||||
|
||||
ret = pthread_cond_timedwait(&cond, &mutex, &ts);
|
||||
if (ret != ETIMEDOUT) {
|
||||
printf("FAIL: pthread_cond_timedwait() (threaded)"
|
||||
" with zero time returned %d\n", ret);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
threadfunc(void *arg)
|
||||
{
|
||||
return NULL;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.2 2004/06/30 03:26:27 jmc Exp $
|
||||
|
||||
WARNS=2
|
||||
|
||||
PROG= condcancel1
|
||||
SRCS= condcancel1.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./condcancel1
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,91 +0,0 @@
|
||||
/* $Id: condcancel1.c,v 1.2 2003/11/21 19:25:50 nathanw Exp $ */
|
||||
|
||||
#include <err.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void *threadfunc(void *);
|
||||
void unlock(void *);
|
||||
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond;
|
||||
int share;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
pthread_t thread;
|
||||
int ret;
|
||||
|
||||
printf("Test of CV state after cancelling a wait\n");
|
||||
|
||||
ret = pthread_mutex_init(&mutex, NULL);
|
||||
if (ret) errx(1, "pthread_mutex_init: %s", strerror(ret));
|
||||
|
||||
ret = pthread_cond_init(&cond, NULL);
|
||||
if (ret) errx(1, "pthread_cond_init: %s", strerror(ret));
|
||||
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
if (ret) errx(1, "pthread_mutex_lock: %s", strerror(ret));
|
||||
|
||||
ret = pthread_create(&thread, NULL, threadfunc, NULL);
|
||||
if (ret) errx(1, "pthread_create: %s", strerror(ret));
|
||||
|
||||
while (share == 0) {
|
||||
ret = pthread_cond_wait(&cond, &mutex);
|
||||
if (ret) errx(1, "pthread_cond_wait: %s", strerror(ret));
|
||||
}
|
||||
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
if (ret) errx(1, "pthread_mutex_unlock: %s", strerror(ret));
|
||||
|
||||
ret = pthread_cancel(thread);
|
||||
if (ret) errx(1, "pthread_cancel: %s", strerror(ret));
|
||||
|
||||
ret = pthread_join(thread, NULL);
|
||||
if (ret) errx(1, "pthread_join: %s", strerror(ret));
|
||||
|
||||
ret = pthread_cond_destroy(&cond);
|
||||
if (ret) errx(1, "pthread_cond_destroy: %s", strerror(ret));
|
||||
|
||||
printf("CV successfully destroyed.\n");
|
||||
|
||||
ret = pthread_mutex_destroy(&mutex);
|
||||
if (ret) errx(1, "pthread_mutex_destroy: %s", strerror(ret));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
threadfunc(void *arg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
if (ret) errx(1, "pthread_mutex_lock: %s", strerror(ret));
|
||||
|
||||
pthread_cleanup_push(unlock, &mutex);
|
||||
|
||||
while (1) {
|
||||
share = 1;
|
||||
ret = pthread_cond_broadcast(&cond);
|
||||
if (ret) errx(1, "pthread_cond_broadcast: %s", strerror(ret));
|
||||
ret = pthread_cond_wait(&cond, &mutex);
|
||||
if (ret) errx(1, "pthread_cond_wait: %s", strerror(ret));
|
||||
}
|
||||
|
||||
pthread_cleanup_pop(0);
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
if (ret) errx(1, "pthread_mutex_unlock: %s", strerror(ret));
|
||||
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
unlock(void *arg)
|
||||
{
|
||||
pthread_mutex_unlock((pthread_mutex_t *)arg);
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2004/07/07 21:53:10 nathanw Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= conddestroy1
|
||||
SRCS= conddestroy1.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./conddestroy1
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,86 +0,0 @@
|
||||
/* $NetBSD: conddestroy1.c,v 1.2 2007/01/20 19:40:06 ad Exp $ */
|
||||
|
||||
/*
|
||||
* XXX This test is bogus. IEEE Std 1003.1, 2004 Edition says:
|
||||
*
|
||||
* If a signal is delivered to a thread waiting for a condition
|
||||
* variable, upon return from the signal handler the thread resumes
|
||||
* waiting for the condition variable as if it was not interrupted,
|
||||
* or it shall return zero due to spurious wakeup.
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void handler(int);
|
||||
void *threadroutine(void *);
|
||||
|
||||
pthread_mutex_t mt;
|
||||
pthread_cond_t cv;
|
||||
|
||||
void
|
||||
handler(int sig)
|
||||
{
|
||||
/* Dummy */
|
||||
return;
|
||||
}
|
||||
|
||||
void *
|
||||
threadroutine(void *arg)
|
||||
{
|
||||
sigset_t set;
|
||||
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGALRM);
|
||||
|
||||
pthread_sigmask(SIG_UNBLOCK, &set, NULL);
|
||||
|
||||
pthread_mutex_lock(&mt);
|
||||
|
||||
/*
|
||||
* Explicitly not a loop; we want to see if the cv is properly
|
||||
* torn down in a spurious wakeup (generated here by SIGALRM).
|
||||
*/
|
||||
pthread_cond_wait(&cv, &mt);
|
||||
|
||||
pthread_mutex_unlock(&mt);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
pthread_t th;
|
||||
sigset_t set;
|
||||
struct sigaction act;
|
||||
|
||||
printf("Testing CV teardown under spurious wakeups.\n");
|
||||
|
||||
sigfillset(&set);
|
||||
|
||||
pthread_sigmask(SIG_BLOCK, &set, NULL);
|
||||
|
||||
act.sa_handler = handler;
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_flags = 0;
|
||||
|
||||
sigaction(SIGALRM, &act, NULL);
|
||||
|
||||
pthread_mutex_init(&mt, NULL);
|
||||
pthread_cond_init(&cv, NULL);
|
||||
|
||||
pthread_create(&th, NULL, threadroutine, NULL);
|
||||
|
||||
alarm(1);
|
||||
|
||||
pthread_join(th, NULL);
|
||||
|
||||
pthread_cond_destroy(&cv);
|
||||
pthread_mutex_destroy(&mt);
|
||||
|
||||
printf("Passed.\n");
|
||||
return 0;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2005/01/21 11:54:24 yamt Exp $
|
||||
|
||||
WARNS=3
|
||||
|
||||
PROG= detach1
|
||||
|
||||
LDADD= -lpthread
|
||||
CPPFLAGS+= -I/usr/src/lib/libpthread/arch/i386
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./${PROG}
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,55 +0,0 @@
|
||||
/* $NetBSD: detach1.c,v 1.1 2005/01/21 11:54:24 yamt Exp $ */
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define NITER 100000
|
||||
|
||||
void *func(void *);
|
||||
int main(void);
|
||||
|
||||
void *
|
||||
func(void *dummy)
|
||||
{
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NITER; i++) {
|
||||
pthread_t t;
|
||||
int error;
|
||||
|
||||
if (pthread_create(&t, NULL, func, NULL)) {
|
||||
/*
|
||||
* sleep and retry once for the case that
|
||||
* the child threads are not finished yet.
|
||||
*/
|
||||
printf("%d sleeping...\n", i);
|
||||
sleep(10);
|
||||
if (pthread_create(&t, NULL, func, NULL))
|
||||
err(1, "create");
|
||||
}
|
||||
|
||||
if (i & 1)
|
||||
sched_yield(); /* give a chance thread to finish */
|
||||
if (pthread_detach(t))
|
||||
err(1, "detach");
|
||||
|
||||
error = pthread_join(t, NULL);
|
||||
if (error != ESRCH && error != EINVAL) {
|
||||
printf("unexpected error %d\n", error);
|
||||
exit(3);
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/07/22 21:27:58 nathanw Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= exit1
|
||||
SRCS= exit1.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./exit1
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,16 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
printf("Test of pthread_exit() in main thread only.\n");
|
||||
|
||||
pthread_exit(NULL);
|
||||
|
||||
printf("You shouldn't see this.");
|
||||
exit(1);
|
||||
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2009/04/02 12:58:44 drochner Exp $
|
||||
|
||||
WARNS=4
|
||||
|
||||
PROG= findthreads
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
sh ${.CURDIR}/findthreads.sh
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,58 +0,0 @@
|
||||
/* $NetBSD: findthreads.c,v 1.2 2010/02/16 00:15:19 mrg Exp $ */
|
||||
|
||||
#include <err.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
static void *
|
||||
f(void *arg)
|
||||
{
|
||||
|
||||
sleep(1000);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define NUM 100
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
pthread_t thr[NUM];
|
||||
int seed, i, j, res, errors;
|
||||
char nam[20];
|
||||
struct rlimit sl;
|
||||
|
||||
if (argc > 1)
|
||||
seed = atoi(argv[1]);
|
||||
else
|
||||
seed = time(0);
|
||||
srandom(seed);
|
||||
getrlimit(RLIMIT_STACK, &sl);
|
||||
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
res = pthread_create(&thr[i], 0, f, 0);
|
||||
if (res)
|
||||
errx(1, "pthread_create iter %d: %s", i, strerror(res));
|
||||
for (j = 0; j <= i; j++) {
|
||||
res = pthread_getname_np(thr[j], nam, sizeof(nam));
|
||||
if (res) {
|
||||
warnx("getname(%d/%d): %s\n", i, j,
|
||||
strerror(res));
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors)
|
||||
break;
|
||||
malloc((random() & 7) * sl.rlim_cur);
|
||||
}
|
||||
if (errors) {
|
||||
printf("%d errors\n", errors);
|
||||
if (argc <= 1)
|
||||
printf("seed was %d\n", seed);
|
||||
}
|
||||
return (!!errors);
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
s=0
|
||||
while expr $s \< 100 >/dev/null; do
|
||||
./findthreads $s || exit 1
|
||||
s=`expr $s + 1`
|
||||
done
|
@ -1,14 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/04/10 18:50:05 lha Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= fork
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./fork
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,76 +0,0 @@
|
||||
/* $NetBSD: fork.c,v 1.3 2003/07/26 19:38:48 salo Exp $ */
|
||||
|
||||
/*
|
||||
* Check that child process doesn't get threads, also make sure sleep
|
||||
* works in child.
|
||||
*
|
||||
* Written by Love Hörnquist Åstrand <lha@NetBSD.org>, March 2003.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static pid_t parent;
|
||||
static int thread_survived = 0;
|
||||
|
||||
static void *
|
||||
print_pid(void *arg)
|
||||
{
|
||||
sleep(3);
|
||||
|
||||
thread_survived = 1;
|
||||
if (parent != getpid()) {
|
||||
kill(parent, SIGKILL);
|
||||
errx(1, "child thread running");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
pthread_t p;
|
||||
pid_t fork_pid;
|
||||
int ret;
|
||||
|
||||
parent = getpid();
|
||||
|
||||
pthread_create(&p, NULL, print_pid, NULL);
|
||||
|
||||
fork_pid = fork();
|
||||
if (fork_pid == -1)
|
||||
err(1, "fork failed");
|
||||
|
||||
if (fork_pid) {
|
||||
ret = pthread_join(p, NULL);
|
||||
if (ret && fork_pid != 0)
|
||||
errx(1, "join failed in parent");
|
||||
|
||||
if (!thread_survived)
|
||||
errx(1, "child_thread did NOT survive");
|
||||
|
||||
if (fork_pid != 0) {
|
||||
int status;
|
||||
waitpid(fork_pid, &status, 0);
|
||||
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
||||
errx(1, "child died wrongly");
|
||||
}
|
||||
} else {
|
||||
sleep(5);
|
||||
|
||||
if (thread_survived) {
|
||||
kill(parent, SIGKILL);
|
||||
errx(1, "child_thread survived");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
PROG=fpu
|
||||
NOMAN=# defined
|
||||
COPTS=-O2
|
||||
LDADD+=-lpthread -lm
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
regress: ${PROG}
|
||||
env PTHREAD_CONCURRENCY=1 ./${PROG}
|
@ -1,118 +0,0 @@
|
||||
/* $NetBSD: fpu.c,v 1.2 2005/12/02 16:44:54 is Exp $ */
|
||||
|
||||
/*
|
||||
* This is adapted from part of csw/cstest of the MPD implementation by
|
||||
* the University of Arizona CS department (http://www.cs.arizona.edu/sr/)
|
||||
* which is in the public domain:
|
||||
*
|
||||
* "The MPD system is in the public domain and you may use and distribute it
|
||||
* as you wish. We ask that you retain credits referencing the University
|
||||
* of Arizona and that you identify any changes you make.
|
||||
*
|
||||
* We can't provide a warranty with MPD; it's up to you to determine its
|
||||
* suitability and reliability for your needs. We would like to hear of
|
||||
* any problems you encounter but we cannot promise a timely correction."
|
||||
*
|
||||
* It was changed to use pthread_create() and sched_yield() instead of
|
||||
* the internal MPD context switching primitives by Ignatios Souvatzis
|
||||
* <is@netbsd.org>.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define N_RECURSE 10
|
||||
|
||||
double mul3(double, double, double);
|
||||
void *stir(void *);
|
||||
void *bar(void *);
|
||||
void dotest(void);
|
||||
|
||||
#define RCTEST(code, mess) if (rc) {fprintf(stderr, "%s\n", mess); exit(1);}
|
||||
#define YIELD() if (sched_yield()) {fprintf(stderr, "sched_yield"); exit(1);}
|
||||
#define LOCK(l) if (pthread_mutex_lock(l)) {fprintf(stderr, "lock"); exit(1);}
|
||||
#define UNLOCK(l) if (pthread_mutex_unlock(l)) {fprintf(stderr, "unlock"); exit(1);}
|
||||
|
||||
int recursion_depth = 0;
|
||||
pthread_mutex_t recursion_depth_lock;
|
||||
pthread_t s5;
|
||||
double stirseed[] = {1.7, 3.2, 2.4};
|
||||
int verbose = 0;
|
||||
|
||||
#define Dprintf(x) if(verbose) printf(x)
|
||||
|
||||
int
|
||||
main(int argc, char *argv[]) {
|
||||
|
||||
int rc;
|
||||
|
||||
printf("Testing threaded floating point computations...");
|
||||
if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'v') {
|
||||
verbose = 1;
|
||||
printf("\n");
|
||||
}
|
||||
rc = pthread_mutex_init(&recursion_depth_lock, 0);
|
||||
if (0 != rc) {
|
||||
fprintf(stderr, "pthread_mutex_init");
|
||||
exit(1);
|
||||
}
|
||||
pthread_create(&s5, 0, stir, stirseed);
|
||||
dotest();
|
||||
|
||||
fprintf(stderr, "\n exiting from main\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void *
|
||||
stir(void *p) {
|
||||
double *q = (double *)p;
|
||||
double x = *q++;
|
||||
double y = *q++;
|
||||
double z = *q++;
|
||||
for (;;) {
|
||||
Dprintf("stirring...");
|
||||
x = sin ((y = cos (x + y + .4)) - (z = cos (x + z + .6)));
|
||||
YIELD();
|
||||
}
|
||||
}
|
||||
|
||||
double mul3(double x, double y, double z) {
|
||||
Dprintf("mul3...");
|
||||
YIELD();
|
||||
Dprintf("returning...\n");
|
||||
return x * y * z;
|
||||
}
|
||||
|
||||
void *bar(void *p) {
|
||||
double d;
|
||||
int rc;
|
||||
|
||||
d = mul3(mul3(2., 3., 5.), mul3(7., 11., 13.),
|
||||
mul3(17., 19., 23.));
|
||||
|
||||
if (d != 223092870.) {
|
||||
printf("\noops - product returned was %.20g\nFAILED\n", d);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
LOCK(&recursion_depth_lock);
|
||||
rc = recursion_depth++;
|
||||
UNLOCK(&recursion_depth_lock);
|
||||
if (rc < N_RECURSE) {
|
||||
dotest();
|
||||
}
|
||||
Dprintf("\n");
|
||||
printf("OK\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void dotest() {
|
||||
pthread_t s2;
|
||||
Dprintf("recursing...");
|
||||
pthread_create(&s2, 0, bar, 0);
|
||||
sleep(20); /* XXX must be long enough for our slowest machine */
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2004/07/27 22:01:51 yamt Exp $
|
||||
|
||||
WARNS=2
|
||||
|
||||
PROG= kill1
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./kill1
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,117 +0,0 @@
|
||||
/* $NetBSD: kill1.c,v 1.2 2006/03/20 00:22:38 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c)2004 YAMAMOTO Takashi,
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define NTHREAD 16
|
||||
struct threadinfo {
|
||||
pthread_t id;
|
||||
sig_atomic_t gotsignal;
|
||||
} th[NTHREAD];
|
||||
|
||||
pthread_t mainthread;
|
||||
|
||||
void sighandler(int);
|
||||
void *f(void *);
|
||||
int main(int, char *[]);
|
||||
|
||||
void
|
||||
sighandler(int signo)
|
||||
{
|
||||
pthread_t self;
|
||||
int i;
|
||||
|
||||
self = pthread_self();
|
||||
if (self == mainthread || signo != SIGUSR1)
|
||||
errx(EXIT_FAILURE, "unexpected signal");
|
||||
|
||||
for (i = 0; i < NTHREAD; i++)
|
||||
if (self == th[i].id)
|
||||
break;
|
||||
|
||||
if (i == NTHREAD)
|
||||
errx(EXIT_FAILURE, "unknown thread");
|
||||
|
||||
th[i].gotsignal++;
|
||||
}
|
||||
|
||||
void *
|
||||
f(void *arg)
|
||||
{
|
||||
struct threadinfo volatile *t = arg;
|
||||
|
||||
while (t->gotsignal < 1) {
|
||||
/* busy loop */
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int ret;
|
||||
int i;
|
||||
pthread_t self;
|
||||
|
||||
mainthread = pthread_self();
|
||||
|
||||
if (SIG_ERR == signal(SIGUSR1, sighandler))
|
||||
err(EXIT_FAILURE, "signal");
|
||||
|
||||
for (i = 0; i < NTHREAD; i++) {
|
||||
ret = pthread_create(&th[i].id, NULL, f, &th[i]);
|
||||
if (ret)
|
||||
err(EXIT_FAILURE, "pthread_create");
|
||||
}
|
||||
|
||||
sched_yield();
|
||||
|
||||
self = pthread_self();
|
||||
if (self != mainthread)
|
||||
errx(EXIT_FAILURE, "thread id changed");
|
||||
|
||||
for (i = 0; i < NTHREAD; i++) {
|
||||
ret = pthread_kill(th[i].id, SIGUSR1);
|
||||
if (ret)
|
||||
err(EXIT_FAILURE, "pthread_kill");
|
||||
}
|
||||
|
||||
for (i = 0; i < NTHREAD; i++) {
|
||||
ret = pthread_join(th[i].id, NULL);
|
||||
if (ret)
|
||||
err(EXIT_FAILURE, "pthread_join");
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/01/30 18:05:25 thorpej Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= mutex1
|
||||
SRCS= mutex1.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./mutex1
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,66 +0,0 @@
|
||||
/* $NetBSD: mutex1.c,v 1.1 2003/01/30 18:05:26 thorpej Exp $ */
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void *threadfunc(void *arg);
|
||||
|
||||
pthread_mutex_t mutex;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int x,ret;
|
||||
pthread_t new;
|
||||
void *joinval;
|
||||
|
||||
printf("1: Mutex-test 1\n");
|
||||
|
||||
pthread_mutex_init(&mutex, NULL);
|
||||
x = 1;
|
||||
pthread_mutex_lock(&mutex);
|
||||
ret = pthread_create(&new, NULL, threadfunc, &x);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_create");
|
||||
printf("1: Before changing the value.\n");
|
||||
sleep(2);
|
||||
x = 20;
|
||||
printf("1: Before releasing the mutex.\n");
|
||||
sleep(2);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
printf("1: After releasing the mutex.\n");
|
||||
ret = pthread_join(new, &joinval);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_join");
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
printf("1: Thread joined. X was %d. Return value (int) was %d\n",
|
||||
x, *(int *)joinval);
|
||||
assert(x == 21);
|
||||
assert(*(int *)joinval == 21);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
threadfunc(void *arg)
|
||||
{
|
||||
int *param;
|
||||
|
||||
printf("2: Second thread.\n");
|
||||
|
||||
param = arg;
|
||||
printf("2: Locking mutex\n");
|
||||
pthread_mutex_lock(&mutex);
|
||||
printf("2: Got mutex. *param = %d\n", *param);
|
||||
assert(*param == 20);
|
||||
(*param)++;
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
return param;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/01/30 18:05:26 thorpej Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= mutex2
|
||||
SRCS= mutex2.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./mutex2
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,81 +0,0 @@
|
||||
/* $NetBSD: mutex2.c,v 1.2 2003/02/03 16:27:32 martin Exp $ */
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void *threadfunc(void *arg);
|
||||
|
||||
pthread_mutex_t mutex;
|
||||
int x;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int count, count2, ret;
|
||||
pthread_t new;
|
||||
void *joinval;
|
||||
|
||||
printf("1: Mutex-test 2\n");
|
||||
|
||||
ret = pthread_mutex_init(&mutex, NULL);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_mutex_init");
|
||||
x = 0;
|
||||
count = count2 = 10000000;
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_mutex_lock (1)");
|
||||
ret = pthread_create(&new, NULL, threadfunc, &count2);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_create");
|
||||
|
||||
printf("1: Thread %p\n", pthread_self());
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_mutex_unlock(1)");
|
||||
|
||||
|
||||
while (count--) {
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_mutex_lock(2)");
|
||||
x++;
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_mutex_unlock(2)");
|
||||
}
|
||||
|
||||
ret = pthread_join(new, &joinval);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_join");
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
printf("1: Thread joined. X was %d. Return value (long) was %ld\n",
|
||||
x, (long)joinval);
|
||||
assert(x == 20000000);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
threadfunc(void *arg)
|
||||
{
|
||||
long count = *(int *)arg;
|
||||
int ret;
|
||||
|
||||
printf("2: Second thread (%p). Count is %ld\n", pthread_self(), count);
|
||||
|
||||
while (count--) {
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_mutex_lock(3)");
|
||||
x++;
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_mutex_unlock(3)");
|
||||
}
|
||||
|
||||
return (void *)count;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/01/30 18:05:26 thorpej Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= mutex3
|
||||
SRCS= mutex3.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./mutex3
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,78 +0,0 @@
|
||||
/* $NetBSD: mutex3.c,v 1.2 2003/02/03 16:27:33 martin Exp $ */
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void *threadfunc(void *arg);
|
||||
|
||||
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
int x;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int count, count2, ret;
|
||||
pthread_t new;
|
||||
void *joinval;
|
||||
|
||||
printf("1: Mutex-test 3\n");
|
||||
|
||||
x = 0;
|
||||
count = count2 = 10000000;
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_mutex_lock (1)");
|
||||
ret = pthread_create(&new, NULL, threadfunc, &count2);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_create");
|
||||
|
||||
printf("1: Thread %p\n", pthread_self());
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_mutex_unlock(1)");
|
||||
|
||||
|
||||
while (count--) {
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_mutex_lock(2)");
|
||||
x++;
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_mutex_unlock(2)");
|
||||
}
|
||||
|
||||
ret = pthread_join(new, &joinval);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_join");
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
printf("1: Thread joined. X was %d. Return value (long) was %ld\n",
|
||||
x, (long)joinval);
|
||||
assert(x == 20000000);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
threadfunc(void *arg)
|
||||
{
|
||||
long count = *(int *)arg;
|
||||
int ret;
|
||||
|
||||
printf("2: Second thread (%p). Count is %ld\n", pthread_self(), count);
|
||||
|
||||
while (count--) {
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_mutex_lock(3)");
|
||||
x++;
|
||||
ret = pthread_mutex_unlock(&mutex);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_mutex_unlock(3)");
|
||||
}
|
||||
|
||||
return (void *)count;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/01/30 18:05:27 thorpej Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= mutex4
|
||||
SRCS= mutex4.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./mutex4
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,83 +0,0 @@
|
||||
/* $NetBSD: mutex4.c,v 1.1 2003/01/30 18:05:27 thorpej Exp $ */
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void *threadfunc(void *arg);
|
||||
|
||||
pthread_mutex_t mutex;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int x,ret;
|
||||
pthread_t new;
|
||||
pthread_mutexattr_t mattr;
|
||||
void *joinval;
|
||||
|
||||
printf("1: Mutex-test 4\n");
|
||||
|
||||
pthread_mutexattr_init(&mattr);
|
||||
pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE);
|
||||
|
||||
pthread_mutex_init(&mutex, &mattr);
|
||||
|
||||
pthread_mutexattr_destroy(&mattr);
|
||||
|
||||
x = 1;
|
||||
pthread_mutex_lock(&mutex);
|
||||
ret = pthread_create(&new, NULL, threadfunc, &x);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_create");
|
||||
|
||||
printf("1: Before recursively acquiring the mutex.\n");
|
||||
ret = pthread_mutex_lock(&mutex);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_mutex_lock recursive");
|
||||
|
||||
printf("1: Before releasing the mutex once.\n");
|
||||
sleep(2);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
printf("1: After releasing the mutex once.\n");
|
||||
|
||||
x = 20;
|
||||
|
||||
printf("1: Before releasing the mutex twice.\n");
|
||||
sleep(2);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
printf("1: After releasing the mutex twice.\n");
|
||||
|
||||
ret = pthread_join(new, &joinval);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_join");
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
printf("1: Thread joined. X was %d. Return value (int) was %d\n",
|
||||
x, *(int *)joinval);
|
||||
assert(x == 21);
|
||||
assert(*(int *)joinval == 21);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
threadfunc(void *arg)
|
||||
{
|
||||
int *param;
|
||||
|
||||
printf("2: Second thread.\n");
|
||||
|
||||
param = arg;
|
||||
printf("2: Locking mutex\n");
|
||||
pthread_mutex_lock(&mutex);
|
||||
printf("2: Got mutex. *param = %d\n", *param);
|
||||
(*param)++;
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
return param;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/02/26 22:05:03 thorpej Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= name
|
||||
SRCS= name.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./name
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,67 +0,0 @@
|
||||
/* $NetBSD: name.c,v 1.2 2003/02/27 15:18:41 hannken Exp $ */
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void *threadfunc(void *arg);
|
||||
|
||||
#define NAME_TOO_LONG "12345678901234567890123456789012" /* 32 chars */
|
||||
#define NAME_JUST_RIGHT "1234567890123456789012345678901" /* 31 chars */
|
||||
|
||||
#define CONST_NAME "xyzzy"
|
||||
char non_const_name[] = CONST_NAME;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
pthread_t thr, self = pthread_self();
|
||||
pthread_attr_t attr;
|
||||
char retname[32];
|
||||
int ret;
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
assert(0 == pthread_attr_getname_np(&attr, retname, sizeof(retname),
|
||||
NULL));
|
||||
assert(retname[0] == '\0');
|
||||
assert(EINVAL == pthread_attr_setname_np(&attr, NAME_TOO_LONG, NULL));
|
||||
assert(0 == pthread_attr_setname_np(&attr, "%s", NAME_JUST_RIGHT));
|
||||
|
||||
strcpy(retname, "foo");
|
||||
assert(0 == pthread_getname_np(self, retname, sizeof(retname)));
|
||||
assert(retname[0] == '\0');
|
||||
|
||||
ret = pthread_create(&thr, &attr, threadfunc, NULL);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_create");
|
||||
|
||||
ret = pthread_join(thr, NULL);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_join");
|
||||
|
||||
assert(ESRCH == pthread_getname_np(thr, retname, sizeof(retname)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
threadfunc(void *arg)
|
||||
{
|
||||
pthread_t self = pthread_self();
|
||||
char retname[32];
|
||||
|
||||
assert(0 == pthread_getname_np(self, retname, sizeof(retname)));
|
||||
assert(0 == strcmp(retname, NAME_JUST_RIGHT));
|
||||
|
||||
assert(0 == pthread_setname_np(self, non_const_name, NULL));
|
||||
memset(non_const_name, 0, sizeof(non_const_name));
|
||||
assert(0 == pthread_getname_np(self, retname, sizeof(retname)));
|
||||
assert(0 == strcmp(retname, CONST_NAME));
|
||||
|
||||
return NULL;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/01/30 19:31:59 thorpej Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= once1
|
||||
SRCS= once1.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./once1
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,35 +0,0 @@
|
||||
/* $NetBSD: once1.c,v 1.1 2003/01/30 19:32:00 thorpej Exp $ */
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
pthread_once_t once = PTHREAD_ONCE_INIT;
|
||||
static int x;
|
||||
|
||||
void ofunc(void);
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
printf("1: Test 1 of pthread_once()\n");
|
||||
|
||||
pthread_once(&once, ofunc);
|
||||
pthread_once(&once, ofunc);
|
||||
|
||||
printf("1: X has value %d\n",x );
|
||||
assert(x == 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
ofunc(void)
|
||||
{
|
||||
|
||||
printf("Variable x has value %d\n", x);
|
||||
x++;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/01/30 19:32:00 thorpej Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= once2
|
||||
SRCS= once2.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./once2
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,61 +0,0 @@
|
||||
/* $NetBSD: once2.c,v 1.1 2003/01/30 19:32:00 thorpej Exp $ */
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
pthread_once_t once = PTHREAD_ONCE_INIT;
|
||||
static int x;
|
||||
|
||||
#define NTHREADS 25
|
||||
|
||||
void ofunc(void);
|
||||
void* threadfunc(void *);
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
pthread_t threads[NTHREADS];
|
||||
int id[NTHREADS];
|
||||
int i;
|
||||
|
||||
printf("1: Test 2 of pthread_once()\n");
|
||||
|
||||
for (i=0; i < NTHREADS; i++) {
|
||||
id[i] = i;
|
||||
pthread_create(&threads[i], NULL, threadfunc, &id[i]);
|
||||
}
|
||||
|
||||
for (i=0; i < NTHREADS; i++)
|
||||
pthread_join(threads[i], NULL);
|
||||
|
||||
printf("1: X has value %d\n",x );
|
||||
assert(x == 2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ofunc(void)
|
||||
{
|
||||
x++;
|
||||
printf("ofunc: Variable x has value %d\n", x);
|
||||
x++;
|
||||
}
|
||||
|
||||
void *
|
||||
threadfunc(void *arg)
|
||||
{
|
||||
int num;
|
||||
|
||||
pthread_once(&once, ofunc);
|
||||
|
||||
num = *(int *)arg;
|
||||
printf("Thread %d sees x with value %d\n", num, x);
|
||||
assert(x == 2);
|
||||
|
||||
return NULL;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2005/07/16 23:02:11 nathanw Exp $
|
||||
|
||||
WARNS=3
|
||||
|
||||
PROG= once3
|
||||
SRCS= once3.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./once3
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,87 +0,0 @@
|
||||
/* $NetBSD: once3.c,v 1.2 2005/07/16 23:12:02 nathanw Exp $ */
|
||||
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
pthread_once_t once = PTHREAD_ONCE_INIT;
|
||||
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void ofunc(void);
|
||||
void* threadfunc(void *);
|
||||
void cleanup(void *);
|
||||
void handler(int, siginfo_t *, void *);
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
pthread_t thread;
|
||||
struct sigaction act;
|
||||
struct itimerval it;
|
||||
printf("Test 3 of pthread_once() (test versus cancellation)\n");
|
||||
|
||||
act.sa_sigaction = handler;
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_flags = SA_SIGINFO;
|
||||
sigaction(SIGALRM, &act, NULL);
|
||||
|
||||
timerclear(&it.it_value);
|
||||
it.it_value.tv_usec = 500000;
|
||||
timerclear(&it.it_interval);
|
||||
setitimer(ITIMER_REAL, &it, NULL);
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
pthread_create(&thread, NULL, threadfunc, NULL);
|
||||
pthread_cancel(thread);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
pthread_join(thread, NULL);
|
||||
|
||||
pthread_once(&once, ofunc);
|
||||
|
||||
/* Cancel timer */
|
||||
timerclear(&it.it_value);
|
||||
setitimer(ITIMER_REAL, &it, NULL);
|
||||
|
||||
printf("Test succeeded\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
cleanup(void *m)
|
||||
{
|
||||
pthread_mutex_t *mu = m;
|
||||
|
||||
pthread_mutex_unlock(mu);
|
||||
}
|
||||
|
||||
void
|
||||
ofunc(void)
|
||||
{
|
||||
|
||||
pthread_testcancel();
|
||||
}
|
||||
|
||||
void *
|
||||
threadfunc(void *arg)
|
||||
{
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
pthread_cleanup_push(cleanup, &mutex);
|
||||
pthread_once(&once, ofunc);
|
||||
pthread_cleanup_pop(1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
handler(int sig, siginfo_t *info, void *ctx)
|
||||
{
|
||||
printf("Signal handler was called; main thread deadlocked in "
|
||||
"pthread_once().\n"
|
||||
"Test failed.\n");
|
||||
exit(1);
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/01/31 20:14:25 skrll Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= preempt1
|
||||
SRCS= preempt1.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
@echo Testing kernel preemption during a large uiomove.
|
||||
./preempt1
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,91 +0,0 @@
|
||||
/* $NetBSD: preempt1.c,v 1.3 2006/04/12 14:01:52 cube Exp $ */
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void *threadfunc(void *arg);
|
||||
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond;
|
||||
int started;
|
||||
|
||||
#define HUGE_BUFFER 1<<20
|
||||
#define NTHREADS 1
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int ret, i;
|
||||
pthread_t new;
|
||||
void *joinval;
|
||||
|
||||
char *mem;
|
||||
int fd;
|
||||
|
||||
mem = malloc(HUGE_BUFFER);
|
||||
if (mem == NULL)
|
||||
err(1, "malloc");
|
||||
|
||||
fd = open("/dev/urandom", O_RDONLY, 0);
|
||||
if (fd == -1)
|
||||
err(1, "open");
|
||||
|
||||
printf("1: preempt test\n");
|
||||
|
||||
pthread_cond_init(&cond, NULL);
|
||||
pthread_mutex_init(&mutex, NULL);
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
started = 0;
|
||||
|
||||
for (i = 0; i < NTHREADS; i++) {
|
||||
ret = pthread_create(&new, NULL, threadfunc, NULL);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_create");
|
||||
}
|
||||
|
||||
while (started < NTHREADS) {
|
||||
pthread_cond_wait(&cond, &mutex);
|
||||
}
|
||||
|
||||
printf("1: Thread has started.\n");
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
printf("1: After releasing the mutex.\n");
|
||||
|
||||
ret = read(fd, mem, HUGE_BUFFER);
|
||||
close(fd);
|
||||
|
||||
assert(ret == HUGE_BUFFER);
|
||||
|
||||
ret = pthread_join(new, &joinval);
|
||||
if (ret != 0)
|
||||
err(1, "pthread_join");
|
||||
|
||||
printf("1: Thread joined.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
threadfunc(void *arg)
|
||||
{
|
||||
printf("2: Second thread.\n");
|
||||
|
||||
printf("2: Locking mutex\n");
|
||||
pthread_mutex_lock(&mutex);
|
||||
printf("2: Got mutex.\n");
|
||||
started++;
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
pthread_cond_signal(&cond);
|
||||
sleep(1);
|
||||
|
||||
return NULL;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2004/05/13 19:17:12 christos Exp $
|
||||
|
||||
NOMAN= # defined
|
||||
|
||||
PROG= resolv
|
||||
|
||||
# Note: this test relies on being dynamically linked. You will get a
|
||||
# spurious PASS for a statically linked test.
|
||||
DPADD+= ${LIBPTHREAD}
|
||||
LDADD+= -lpthread
|
||||
|
||||
regress: ${PROG}
|
||||
./${PROG} ${.CURDIR}/mach
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,92 +0,0 @@
|
||||
above.warped.net
|
||||
anoncvs.cirr.com
|
||||
anoncvs.isc.netbsd.org
|
||||
anoncvs.leo.org
|
||||
anoncvs.netbsd.lt
|
||||
anoncvs.netbsd.ro
|
||||
anoncvs.netbsd.se
|
||||
antioche.antioche.eu.org
|
||||
boulder.tele.dk
|
||||
centaurus.4web.cz
|
||||
chur.math.ntnu.no
|
||||
cnftp.bjpu.edu.cn
|
||||
console.netbsd.org
|
||||
cvs.fi.netbsd.org
|
||||
cvs.mikrolahti.fi
|
||||
cvs.netbsd.org
|
||||
cvsup-netbsd.leo.org
|
||||
cvsup.netbsd.se
|
||||
cvsup.pasta.cs.uit.no
|
||||
ftp.bitcon.no
|
||||
ftp.chg.ru
|
||||
ftp.duth.gr
|
||||
ftp.estpak.ee
|
||||
ftp.fsn.hu
|
||||
ftp.funet.fi
|
||||
ftp.grondar.za
|
||||
ftp.leo.org
|
||||
ftp.netbsd.lt
|
||||
ftp.netbsd.org
|
||||
ftp.nluug.nl
|
||||
ftp.plig.org
|
||||
ftp.uni-erlangen.de
|
||||
ftp.xgate.co.kr
|
||||
gd.tuwien.ac.at
|
||||
gort.ludd.luth.se
|
||||
grappa.unix-ag.uni-kl.de
|
||||
info.wins.uva.nl
|
||||
irc.warped.net
|
||||
knug.youn.co.kr
|
||||
lala.iri.co.jp
|
||||
mail.jp.netbsd.org
|
||||
mail.kr.netbsd.org
|
||||
mail.netbsd.org
|
||||
melanoma.cs.rmit.edu.au
|
||||
mirror.aarnet.edu.au
|
||||
mirror.netbsd.com.br
|
||||
mirror03.inet.tele.dk
|
||||
moon.vub.ac.be
|
||||
nbwww.sergei.cc
|
||||
net.bsd.cz
|
||||
netbsd.3miasto.net
|
||||
netbsd.4ka.mipt.ru
|
||||
netbsd.apk.od.ua
|
||||
netbsd.csie.nctu.edu.tw
|
||||
netbsd.enderunix.org
|
||||
netbsd.ftp.fu-berlin.de
|
||||
netbsd.netlead.com.au
|
||||
netbsd.nsysu.edu.tw
|
||||
netbsd.pair.com
|
||||
netbsd.stevens-tech.edu
|
||||
netbsd.triada.bg
|
||||
netbsd.unix.net.nz
|
||||
netbsd.unixtech.be
|
||||
netbsd.vejas.lt
|
||||
netbsd.wagener-consulting.lu
|
||||
netbsd.zarco.org
|
||||
netbsdiso.interoute.net.uk
|
||||
netbsdwww.bitcon.no
|
||||
netbsdwww.cordef.com.pl
|
||||
netbsdwww.cs.rmit.edu.au
|
||||
netbsdwww.interoute.net.uk
|
||||
news.gw.com
|
||||
ns.netbsd.org
|
||||
pigu.iri.co.jp
|
||||
pluto.cdpa.nsysu.edu.tw
|
||||
projects.slowass.net
|
||||
server6.pasta.cs.uit.no
|
||||
skeleton.phys.spbu.ru
|
||||
snoopy.allbsd.org
|
||||
spike.allbsd.org
|
||||
sundry.netbsd.org
|
||||
tanya.sergei.cc
|
||||
web-a.fi.gw.com
|
||||
web-a.us.gw.com
|
||||
web.netbsd.mirror.arhea.net
|
||||
www.en.netbsd.de
|
||||
www.netbsd.cl
|
||||
www.netbsd.nl
|
||||
www.netbsd.org
|
||||
www.netbsd.ro
|
||||
zathras.netbsd.org
|
||||
zeppo.rediris.es
|
@ -1,205 +0,0 @@
|
||||
/* $NetBSD: resolv.c,v 1.8 2008/08/17 00:19:52 gmcgarry Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2004 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: resolv.c,v 1.8 2008/08/17 00:19:52 gmcgarry Exp $");
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <netdb.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
#include <string.h>
|
||||
#include <stringlist.h>
|
||||
|
||||
#define NTHREADS 10
|
||||
#define NHOSTS 100
|
||||
#define WS " \t\n\r"
|
||||
|
||||
static StringList *hosts = NULL;
|
||||
static int debug = 0;
|
||||
static int *ask = NULL;
|
||||
static int *got = NULL;
|
||||
|
||||
static void usage(void) __attribute__((__noreturn__));
|
||||
static void load(const char *);
|
||||
static void resolvone(int);
|
||||
static void *resolvloop(void *);
|
||||
static void run(int *);
|
||||
|
||||
static pthread_mutex_t stats = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"Usage: %s [-d] [-h <nhosts>] [-n <nthreads>] <file> ...\n",
|
||||
getprogname());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
load(const char *fname)
|
||||
{
|
||||
FILE *fp;
|
||||
size_t len;
|
||||
char *line;
|
||||
|
||||
if ((fp = fopen(fname, "r")) == NULL)
|
||||
err(1, "Cannot open `%s'", fname);
|
||||
while ((line = fgetln(fp, &len)) != NULL) {
|
||||
char c = line[len];
|
||||
char *ptr;
|
||||
line[len] = '\0';
|
||||
for (ptr = strtok(line, WS); ptr; ptr = strtok(NULL, WS))
|
||||
sl_add(hosts, strdup(ptr));
|
||||
line[len] = c;
|
||||
}
|
||||
|
||||
(void)fclose(fp);
|
||||
}
|
||||
|
||||
static void
|
||||
resolvone(int n)
|
||||
{
|
||||
char buf[1024];
|
||||
pthread_t self = pthread_self();
|
||||
size_t i = (random() & 0x0fffffff) % hosts->sl_cur;
|
||||
char *host = hosts->sl_str[i];
|
||||
struct addrinfo *res;
|
||||
int error, len;
|
||||
if (debug) {
|
||||
len = snprintf(buf, sizeof(buf), "%p: %d resolving %s %d\n",
|
||||
self, n, host, (int)i);
|
||||
(void)write(STDOUT_FILENO, buf, len);
|
||||
}
|
||||
error = getaddrinfo(host, NULL, NULL, &res);
|
||||
if (debug) {
|
||||
len = snprintf(buf, sizeof(buf), "%p: host %s %s\n",
|
||||
self, host, error ? "not found" : "ok");
|
||||
(void)write(STDOUT_FILENO, buf, len);
|
||||
}
|
||||
pthread_mutex_lock(&stats);
|
||||
ask[i]++;
|
||||
got[i] += error == 0;
|
||||
pthread_mutex_unlock(&stats);
|
||||
if (error == 0)
|
||||
freeaddrinfo(res);
|
||||
}
|
||||
|
||||
static void *
|
||||
resolvloop(void *p)
|
||||
{
|
||||
int *nhosts = (int *)p;
|
||||
if (*nhosts == 0)
|
||||
return NULL;
|
||||
do
|
||||
resolvone(*nhosts);
|
||||
while (--(*nhosts));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
run(int *nhosts)
|
||||
{
|
||||
pthread_t self = pthread_self();
|
||||
if (pthread_create(&self, NULL, resolvloop, nhosts) != 0)
|
||||
err(1, "pthread_create");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int nthreads = NTHREADS;
|
||||
int nhosts = NHOSTS;
|
||||
int i, c, done, *nleft;
|
||||
hosts = sl_init();
|
||||
|
||||
srandom(1234);
|
||||
|
||||
while ((c = getopt(argc, argv, "dh:n:")) != -1)
|
||||
switch (c) {
|
||||
case 'd':
|
||||
debug++;
|
||||
break;
|
||||
case 'h':
|
||||
nhosts = atoi(optarg);
|
||||
break;
|
||||
case 'n':
|
||||
nthreads = atoi(optarg);
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
|
||||
for (i = optind; i < argc; i++)
|
||||
load(argv[i]);
|
||||
|
||||
if (hosts->sl_cur == 0)
|
||||
usage();
|
||||
|
||||
if ((nleft = malloc(nthreads * sizeof(int))) == NULL)
|
||||
err(1, "malloc");
|
||||
if ((ask = calloc(hosts->sl_cur, sizeof(int))) == NULL)
|
||||
err(1, "calloc");
|
||||
if ((got = calloc(hosts->sl_cur, sizeof(int))) == NULL)
|
||||
err(1, "calloc");
|
||||
|
||||
|
||||
for (i = 0; i < nthreads; i++) {
|
||||
nleft[i] = nhosts;
|
||||
run(&nleft[i]);
|
||||
}
|
||||
|
||||
for (done = 0; !done;) {
|
||||
done = 1;
|
||||
for (i = 0; i < nthreads; i++) {
|
||||
if (nleft[i] != 0) {
|
||||
done = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
c = 0;
|
||||
for (i = 0; i < hosts->sl_cur; i++) {
|
||||
if (ask[i] != got[i] && got[i] != 0) {
|
||||
warnx("Error: host %s ask %d got %d\n",
|
||||
hosts->sl_str[i], ask[i], got[i]);
|
||||
c++;
|
||||
}
|
||||
}
|
||||
free(nleft);
|
||||
free(ask);
|
||||
free(got);
|
||||
sl_free(hosts, 1);
|
||||
return c;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2004/08/03 11:36:23 yamt Exp $
|
||||
|
||||
WARNS=3
|
||||
|
||||
PROG= rwlock1
|
||||
SRCS= rwlock1.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./rwlock1
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,107 +0,0 @@
|
||||
/* $NetBSD: rwlock1.c,v 1.2 2004/08/03 12:02:09 yamt Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c)2004 YAMAMOTO Takashi,
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
pthread_rwlock_t lk;
|
||||
|
||||
int main(void);
|
||||
void *do_nothing(void *);
|
||||
|
||||
struct timespec to;
|
||||
|
||||
/* ARGSUSED */
|
||||
void *
|
||||
do_nothing(void *dummy)
|
||||
{
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
int error;
|
||||
pthread_t t;
|
||||
|
||||
error = pthread_create(&t, NULL, do_nothing, NULL);
|
||||
if (error)
|
||||
exit(1000);
|
||||
|
||||
error = pthread_rwlock_init(&lk, NULL);
|
||||
if (error)
|
||||
exit(1);
|
||||
|
||||
error = pthread_rwlock_rdlock(&lk);
|
||||
if (error)
|
||||
exit(2);
|
||||
|
||||
error = pthread_rwlock_rdlock(&lk);
|
||||
if (error)
|
||||
exit(3);
|
||||
|
||||
error = pthread_rwlock_unlock(&lk);
|
||||
if (error)
|
||||
exit(4);
|
||||
|
||||
error = pthread_rwlock_trywrlock(&lk);
|
||||
if (error != EBUSY)
|
||||
exit(5);
|
||||
|
||||
if (clock_gettime(CLOCK_REALTIME, &to))
|
||||
err(101, "clock_gettime");
|
||||
to.tv_sec++;
|
||||
error = pthread_rwlock_timedwrlock(&lk, &to);
|
||||
if (error != ETIMEDOUT && error != EDEADLK)
|
||||
exit(6);
|
||||
|
||||
error = pthread_rwlock_unlock(&lk);
|
||||
if (error)
|
||||
exit(7);
|
||||
|
||||
if (clock_gettime(CLOCK_REALTIME, &to))
|
||||
err(102, "clock_gettime");
|
||||
to.tv_sec++;
|
||||
error = pthread_rwlock_timedwrlock(&lk, &to);
|
||||
if (error)
|
||||
exit(8);
|
||||
|
||||
if (clock_gettime(CLOCK_REALTIME, &to))
|
||||
err(103, "clock_gettime");
|
||||
to.tv_sec++;
|
||||
error = pthread_rwlock_timedwrlock(&lk, &to);
|
||||
if (error != ETIMEDOUT && error != EDEADLK)
|
||||
exit(9);
|
||||
|
||||
exit(0);
|
||||
|
||||
/* NOTREACHED */
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/01/20 20:12:18 christos Exp $
|
||||
|
||||
NOMAN= # defined
|
||||
|
||||
PROG= sem
|
||||
LDADD+= -lpthread
|
||||
|
||||
regress:
|
||||
@echo Testing POSIX 1003.1b semaphores
|
||||
./sem
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,167 +0,0 @@
|
||||
/* $NetBSD: sem.c,v 1.4 2006/04/18 12:21:05 simonb Exp $ */
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2000 Jason Evans <jasone@freebsd.org>.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice(s), this list of conditions and the following disclaimer as
|
||||
* the first lines of this file unmodified other than the possible
|
||||
* addition of one or more copyright notices.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice(s), this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************
|
||||
*
|
||||
* sem test.
|
||||
*
|
||||
* $FreeBSD: src/lib/libpthread/test/sem_d.c,v 1.2 2001/05/20 23:11:09 jasone Exp $
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <semaphore.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define NTHREADS 10
|
||||
|
||||
#define _LIBC_R_
|
||||
|
||||
static void *
|
||||
entry(void * a_arg)
|
||||
{
|
||||
pthread_t self = pthread_self();
|
||||
sem_t * sem = (sem_t *) a_arg;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Thread %p waiting for semaphore...\n", self);
|
||||
#endif
|
||||
sem_wait(sem);
|
||||
#ifdef DEBUG
|
||||
printf("Thread %p got semaphore\n", self);
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void ksem(void);
|
||||
static void usem(void);
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
|
||||
assert(-1 != sysconf(_SC_SEMAPHORES));
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Test begin\n");
|
||||
#endif
|
||||
usem();
|
||||
ksem();
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Test end\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
usem()
|
||||
{
|
||||
sem_t sem_a, sem_b;
|
||||
pthread_t threads[NTHREADS];
|
||||
unsigned i;
|
||||
int val;
|
||||
|
||||
/* userland sem */
|
||||
assert(0 == sem_init(&sem_b, 0, 0));
|
||||
assert(0 == sem_getvalue(&sem_b, &val));
|
||||
assert(0 == val);
|
||||
|
||||
assert(0 == sem_post(&sem_b));
|
||||
assert(0 == sem_getvalue(&sem_b, &val));
|
||||
assert(1 == val);
|
||||
|
||||
assert(0 == sem_wait(&sem_b));
|
||||
assert(-1 == sem_trywait(&sem_b));
|
||||
assert(EAGAIN == errno);
|
||||
assert(0 == sem_post(&sem_b));
|
||||
assert(0 == sem_trywait(&sem_b));
|
||||
assert(0 == sem_post(&sem_b));
|
||||
assert(0 == sem_wait(&sem_b));
|
||||
assert(0 == sem_post(&sem_b));
|
||||
|
||||
|
||||
assert(0 == sem_destroy(&sem_b));
|
||||
|
||||
assert(0 == sem_init(&sem_a, 0, 0));
|
||||
|
||||
for (i = 0; i < NTHREADS; i++) {
|
||||
pthread_create(&threads[i], NULL, entry, (void *) &sem_a);
|
||||
}
|
||||
|
||||
for (i = 0; i < NTHREADS; i++) {
|
||||
sleep(1);
|
||||
#ifdef DEBUG
|
||||
printf("main loop 1: posting...\n");
|
||||
#endif
|
||||
assert(0 == sem_post(&sem_a));
|
||||
}
|
||||
|
||||
for (i = 0; i < NTHREADS; i++) {
|
||||
pthread_join(threads[i], NULL);
|
||||
}
|
||||
|
||||
for (i = 0; i < NTHREADS; i++) {
|
||||
pthread_create(&threads[i], NULL, entry, (void *) &sem_a);
|
||||
}
|
||||
|
||||
for (i = 0; i < NTHREADS; i++) {
|
||||
sleep(1);
|
||||
#ifdef DEBUG
|
||||
printf("main loop 2: posting...\n");
|
||||
#endif
|
||||
assert(0 == sem_post(&sem_a));
|
||||
}
|
||||
|
||||
for (i = 0; i < NTHREADS; i++) {
|
||||
pthread_join(threads[i], NULL);
|
||||
}
|
||||
|
||||
assert(0 == sem_destroy(&sem_a));
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
ksem()
|
||||
{
|
||||
sem_t *sem;
|
||||
|
||||
(void)sem_unlink("/foo");
|
||||
sem = sem_open("/foo", O_CREAT | O_EXCL, 0644, 0);
|
||||
assert(sem != SEM_FAILED);
|
||||
assert(-1 != sem_close(sem));
|
||||
assert(-1 != sem_unlink("/foo"));
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2004/11/03 15:18:35 yamt Exp $
|
||||
|
||||
WARNS=2
|
||||
|
||||
PROG= sem2
|
||||
|
||||
LDADD+= -lpthread
|
||||
LDADD+= -lrt
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./${PROG}
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,113 +0,0 @@
|
||||
/* $NetBSD: sem2.c,v 1.1 2004/11/03 15:18:35 yamt Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c)2004 YAMAMOTO Takashi,
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
sem_t sem;
|
||||
|
||||
void sighandler(int);
|
||||
void *f(void *);
|
||||
int main(int, char *[]);
|
||||
|
||||
void
|
||||
sighandler(int signo)
|
||||
{
|
||||
|
||||
/* printf("signal %d\n", signo); */
|
||||
|
||||
if (signo != SIGALRM)
|
||||
errx(EXIT_FAILURE, "unexpected signal %d", signo);
|
||||
|
||||
if (sem_post(&sem))
|
||||
err(EXIT_FAILURE, "sem_post");
|
||||
}
|
||||
|
||||
void *
|
||||
f(void *arg)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 10; ) {
|
||||
int ret;
|
||||
|
||||
if ((i & 1) != 0)
|
||||
ret = sem_wait(&sem);
|
||||
else
|
||||
ret = sem_trywait(&sem);
|
||||
if (ret) {
|
||||
if ((i & 1) !=0 || errno != EAGAIN)
|
||||
err(EXIT_FAILURE, "sem_trywait");
|
||||
continue;
|
||||
}
|
||||
printf("%s: %d\n", __func__, i);
|
||||
alarm(1);
|
||||
i++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
#if defined(USE_PTHREAD)
|
||||
int ret;
|
||||
pthread_t t;
|
||||
#endif
|
||||
|
||||
alarm(1);
|
||||
|
||||
if (sem_init(&sem, 0, 0))
|
||||
err(EXIT_FAILURE, "sem_init");
|
||||
|
||||
#if defined(USE_PTHREAD)
|
||||
ret = pthread_create(&t, NULL, f, NULL);
|
||||
if (ret)
|
||||
err(EXIT_FAILURE, "pthread_create");
|
||||
#endif
|
||||
|
||||
if (SIG_ERR == signal(SIGALRM, sighandler))
|
||||
err(EXIT_FAILURE, "signal");
|
||||
|
||||
#if defined(USE_PTHREAD)
|
||||
ret = pthread_join(t, NULL);
|
||||
if (ret)
|
||||
err(EXIT_FAILURE, "pthread_join");
|
||||
#else
|
||||
f(NULL);
|
||||
#endif
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2003/09/12 21:15:06 christos Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= sigalarm
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./sigalarm
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,74 +0,0 @@
|
||||
/* $NetBSD: sigalarm.c,v 1.2 2007/09/09 01:08:56 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Regression test for sigsuspend in libpthread when pthread lib is
|
||||
* initialized.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
int alarm_set;
|
||||
|
||||
#ifdef SA_SIGINFO
|
||||
static void alarm_handler(int, siginfo_t *, void *);
|
||||
static void
|
||||
alarm_handler(int signo, siginfo_t *si, void *ctx)
|
||||
{
|
||||
if (si->si_signo != signo)
|
||||
errx(1, "Received unexpected signal %d", signo);
|
||||
alarm_set = 1;
|
||||
}
|
||||
#else
|
||||
static void alarm_handler(int);
|
||||
static void
|
||||
alarm_handler(int signo)
|
||||
{
|
||||
if (SIGALRM != signo)
|
||||
errx(1, "Received unexpected signal %d", signo);
|
||||
alarm_set = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void *
|
||||
setup(void *dummy)
|
||||
{
|
||||
struct sigaction sa;
|
||||
sigset_t ss;
|
||||
#ifdef SA_SIGINFO
|
||||
sa.sa_flags = SA_SIGINFO;
|
||||
sa.sa_sigaction = alarm_handler;
|
||||
#else
|
||||
sa.sa_flags = 0;
|
||||
sa.sa_handler = alarm_handler;
|
||||
#endif
|
||||
sigfillset(&ss);
|
||||
sigprocmask(SIG_SETMASK, &ss, NULL);
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sigaction(SIGALRM, &sa, NULL);
|
||||
alarm(1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
sigset_t set;
|
||||
pthread_t self = pthread_self();
|
||||
|
||||
if (pthread_create(&self, NULL, setup, NULL) != 0)
|
||||
err(1, "Cannot create thread");
|
||||
|
||||
sigemptyset(&set);
|
||||
sigsuspend(&set);
|
||||
alarm(0);
|
||||
|
||||
if (!alarm_set)
|
||||
errx(1, "alarm_set not set");
|
||||
return 0;
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2004/01/02 19:27:06 cl Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= siglongjmp1
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./siglongjmp1
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,72 +0,0 @@
|
||||
/* $NetBSD: siglongjmp1.c,v 1.1 2004/01/02 19:27:06 cl Exp $ */
|
||||
|
||||
/*
|
||||
* Regression test for siglongjmp out of a signal handler back into
|
||||
* its thread.
|
||||
*
|
||||
* Written by Christian Limpach <cl@NetBSD.org>, December 2003.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <pthread.h>
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/resource.h>
|
||||
|
||||
void *thread(void *);
|
||||
void handler(int, siginfo_t *, void *);
|
||||
static sigjmp_buf env;
|
||||
|
||||
void *
|
||||
thread(void *arg)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
handler(int sig, siginfo_t *info, void *ctx)
|
||||
{
|
||||
siglongjmp(env, 1);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
pthread_t t;
|
||||
sigset_t nset;
|
||||
struct rlimit rlim;
|
||||
struct sigaction act;
|
||||
|
||||
rlim.rlim_cur = rlim.rlim_max = 0;
|
||||
(void)setrlimit(RLIMIT_CORE, &rlim);
|
||||
|
||||
pthread_create(&t, NULL, thread, NULL);
|
||||
|
||||
sigemptyset(&nset);
|
||||
sigaddset(&nset, SIGUSR1);
|
||||
pthread_sigmask(SIG_SETMASK, &nset, NULL);
|
||||
|
||||
act.sa_sigaction = handler;
|
||||
sigemptyset(&act.sa_mask);
|
||||
sigaddset(&act.sa_mask, SIGUSR2);
|
||||
act.sa_flags = 0;
|
||||
sigaction(SIGSEGV, &act, NULL);
|
||||
|
||||
if (sigsetjmp(env, 1) == 0)
|
||||
*(long *)0 = 0;
|
||||
|
||||
pthread_sigmask(0, NULL, &nset);
|
||||
|
||||
if (sigismember(&nset, SIGSEGV))
|
||||
errx(1, "SIGSEGV set");
|
||||
if (sigismember(&nset, SIGUSR2))
|
||||
errx(1, "SIGUSR2 set");
|
||||
if (!sigismember(&nset, SIGUSR1))
|
||||
errx(1, "SIGUSR1 not set");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2004/01/02 19:26:24 cl Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= sigmask1
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./sigmask1
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,33 +0,0 @@
|
||||
/* $NetBSD: sigmask1.c,v 1.1 2004/01/02 19:26:24 cl Exp $ */
|
||||
|
||||
/*
|
||||
* Regression test for pthread_sigmask when SA upcalls aren't started yet.
|
||||
*
|
||||
* Written by Christian Limpach <cl@NetBSD.org>, December 2003.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/resource.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
sigset_t nset;
|
||||
struct rlimit rlim;
|
||||
|
||||
rlim.rlim_cur = rlim.rlim_max = 0;
|
||||
(void)setrlimit(RLIMIT_CORE, &rlim);
|
||||
|
||||
sigemptyset(&nset);
|
||||
sigaddset(&nset, SIGFPE);
|
||||
pthread_sigmask(SIG_BLOCK, &nset, NULL);
|
||||
|
||||
kill(getpid(), SIGFPE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2005/02/26 20:03:25 nathanw Exp $
|
||||
|
||||
WARNS=2
|
||||
|
||||
PROG= sigmask2
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./sigmask2
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,63 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Test that signal masks are respected before threads are started */
|
||||
volatile sig_atomic_t flag;
|
||||
|
||||
void handler1(int sig, siginfo_t *info, void *ctx);
|
||||
void handler2(int sig, siginfo_t *info, void *ctx);
|
||||
|
||||
void
|
||||
handler1(int sig, siginfo_t *info, void *ctx)
|
||||
{
|
||||
|
||||
kill(getpid(), SIGUSR2);
|
||||
/*
|
||||
* If the mask is properly set, SIGUSR2 will not be handled
|
||||
* until this handler returns.
|
||||
*/
|
||||
flag = 1;
|
||||
}
|
||||
|
||||
void
|
||||
handler2(int sig, siginfo_t *info, void *ctx)
|
||||
{
|
||||
if (flag == 1)
|
||||
flag = 2;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
struct sigaction act;
|
||||
int ret;
|
||||
|
||||
act.sa_sigaction = handler1;
|
||||
sigemptyset(&act.sa_mask);
|
||||
sigaddset(&act.sa_mask, SIGUSR2);
|
||||
act.sa_flags = SA_SIGINFO;
|
||||
|
||||
ret = sigaction(SIGUSR1, &act, NULL);
|
||||
if (ret) {
|
||||
printf("sigaction: %d\n", ret);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
act.sa_sigaction = handler2;
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_flags = SA_SIGINFO;
|
||||
ret = sigaction(SIGUSR2, &act, NULL);
|
||||
|
||||
kill(getpid(), SIGUSR1);
|
||||
|
||||
if (flag == 2)
|
||||
printf("Success: Both handlers ran in order\n");
|
||||
else {
|
||||
printf("Failure: flag was %d\n", (int)flag);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2005/02/26 20:08:14 nathanw Exp $
|
||||
|
||||
WARNS=2
|
||||
|
||||
PROG= sigmask3
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./sigmask3
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,95 +0,0 @@
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Test that signal masks are respected while threads are running. */
|
||||
volatile sig_atomic_t flag;
|
||||
volatile sig_atomic_t flag2;
|
||||
|
||||
volatile pthread_t thr_usr1;
|
||||
volatile pthread_t thr_usr2;
|
||||
|
||||
void handler1(int, siginfo_t *, void *);
|
||||
void handler2(int, siginfo_t *, void *);
|
||||
void *threadroutine(void *);
|
||||
|
||||
void
|
||||
handler1(int sig, siginfo_t *info, void *ctx)
|
||||
{
|
||||
|
||||
kill(getpid(), SIGUSR2);
|
||||
/*
|
||||
* If the mask is properly set, SIGUSR2 will not be handled
|
||||
* by the current thread until this handler returns.
|
||||
*/
|
||||
flag = 1;
|
||||
thr_usr1 = pthread_self();
|
||||
}
|
||||
|
||||
void
|
||||
handler2(int sig, siginfo_t *info, void *ctx)
|
||||
{
|
||||
if (flag == 1)
|
||||
flag = 2;
|
||||
flag2 = 1;
|
||||
thr_usr2 = pthread_self();
|
||||
}
|
||||
|
||||
void *
|
||||
threadroutine(void *arg)
|
||||
{
|
||||
|
||||
kill(getpid(), SIGUSR1);
|
||||
sleep(1);
|
||||
|
||||
if (flag == 2)
|
||||
printf("Success: Both handlers ran in order\n");
|
||||
else if (flag == 1 && flag2 == 1 && thr_usr1 != thr_usr2)
|
||||
printf("Success: Handlers were invoked by different threads\n");
|
||||
else {
|
||||
printf("Failure: flag=%d, flag2=%d, thr1=%p, thr2=%p\n",
|
||||
(int)flag, (int)flag2, (void *)thr_usr1, (void *)thr_usr2);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
struct sigaction act;
|
||||
pthread_t thread;
|
||||
int ret;
|
||||
|
||||
act.sa_sigaction = handler1;
|
||||
sigemptyset(&act.sa_mask);
|
||||
sigaddset(&act.sa_mask, SIGUSR2);
|
||||
act.sa_flags = SA_SIGINFO;
|
||||
|
||||
ret = sigaction(SIGUSR1, &act, NULL);
|
||||
if (ret) {
|
||||
printf("sigaction: %d\n", ret);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
act.sa_sigaction = handler2;
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_flags = SA_SIGINFO;
|
||||
ret = sigaction(SIGUSR2, &act, NULL);
|
||||
|
||||
ret = pthread_create(&thread, NULL, threadroutine, NULL);
|
||||
if (ret) {
|
||||
printf("pthread_create: %d\n", ret);
|
||||
exit(1);
|
||||
}
|
||||
ret = pthread_join(thread, NULL);
|
||||
if (ret) {
|
||||
printf("pthread_join: %d\n", ret);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2005/07/26 20:44:47 christos Exp $
|
||||
|
||||
WARNS=3
|
||||
|
||||
PROG= sigmask4
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./sigmask4
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Create a thread that is running [the sleeper] with a signal blocked
|
||||
* and use the other thread to block on select. This is so that we can
|
||||
* send the signal on the "select" thread. Interrupt the selected thread
|
||||
* with alarm. Detects bug in libpthread where we did not use the proper
|
||||
* signal mask, so only the first signal got delivered.
|
||||
*/
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
|
||||
static sig_atomic_t count = 0;
|
||||
|
||||
static void
|
||||
handler(int sig)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
static void *
|
||||
sleeper(void* arg)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 10; i++)
|
||||
sleep(1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
pthread_t id;
|
||||
struct sigaction act;
|
||||
|
||||
act.sa_sigaction = NULL;
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_flags = 0;
|
||||
act.sa_handler = handler;
|
||||
|
||||
if (sigaction(SIGALRM, &act, NULL) == -1)
|
||||
err(1, "sigaction");
|
||||
|
||||
sigaddset(&act.sa_mask, SIGALRM);
|
||||
pthread_sigmask(SIG_SETMASK, &act.sa_mask, NULL);
|
||||
|
||||
pthread_create(&id, NULL, sleeper, NULL);
|
||||
sleep(1);
|
||||
|
||||
sigemptyset(&act.sa_mask);
|
||||
pthread_sigmask(SIG_SETMASK, &act.sa_mask, NULL);
|
||||
|
||||
for (;;) {
|
||||
alarm(1);
|
||||
if (select(1, NULL, NULL, NULL, NULL) == -1 && errno == EINTR)
|
||||
if (count == 2)
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.2 2003/03/02 06:07:23 dogcow Exp $
|
||||
|
||||
WARNS=1
|
||||
|
||||
PROG= sigsuspend
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./sigsuspend
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,52 +0,0 @@
|
||||
/* $NetBSD: sigsuspend.c,v 1.2 2003/07/26 19:38:48 salo Exp $ */
|
||||
|
||||
/*
|
||||
* Regression test for sigsuspend in libpthread when pthread lib isn't
|
||||
* initialized.
|
||||
*
|
||||
* Written by Love Hörnquist Åstrand <lha@NetBSD.org>, March 2003.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static void alarm_handler(int);
|
||||
|
||||
int alarm_set;
|
||||
|
||||
static void
|
||||
alarm_handler(int signo)
|
||||
{
|
||||
alarm_set = 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct sigaction sa;
|
||||
sigset_t set;
|
||||
|
||||
sa.sa_flags = 0;
|
||||
sa.sa_handler = alarm_handler;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
|
||||
sigaction(SIGALRM, &sa, NULL);
|
||||
|
||||
alarm(1);
|
||||
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGUSR1);
|
||||
|
||||
sigsuspend(&set);
|
||||
|
||||
alarm(0);
|
||||
|
||||
if (!alarm_set)
|
||||
errx(1, "alarm_set not set");
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.1 2005/04/19 16:36:34 nathanw Exp $
|
||||
|
||||
WARNS=3
|
||||
|
||||
PROG= sleep1
|
||||
SRCS= sleep1.c
|
||||
|
||||
LDADD= -lpthread
|
||||
|
||||
NOMAN=
|
||||
|
||||
regress:
|
||||
./sleep1
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,63 +0,0 @@
|
||||
/* $NetBSD: sleep1.c,v 1.3 2009/03/08 19:17:11 christos Exp $ */
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
void *threadfunc(void *);
|
||||
void handler(int);
|
||||
|
||||
#define LONGTIME 2000000000
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
pthread_t thread;
|
||||
struct itimerval it;
|
||||
struct sigaction act;
|
||||
sigset_t mtsm;
|
||||
|
||||
printf("Testing sleeps unreasonably far into the future.\n");
|
||||
|
||||
act.sa_handler = handler;
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_flags = 0;
|
||||
sigaction(SIGALRM, &act, NULL);
|
||||
|
||||
pthread_create(&thread, NULL, threadfunc, NULL);
|
||||
|
||||
/* make sure the signal is delivered to the child thread */
|
||||
sigemptyset(&mtsm);
|
||||
sigaddset(&mtsm, SIGALRM);
|
||||
pthread_sigmask(SIG_BLOCK, &mtsm, 0);
|
||||
|
||||
timerclear(&it.it_interval);
|
||||
timerclear(&it.it_value);
|
||||
it.it_value.tv_sec = 1;
|
||||
setitimer(ITIMER_REAL, &it, NULL);
|
||||
|
||||
pthread_join(thread, NULL);
|
||||
|
||||
printf("Passed.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
threadfunc(void *arg)
|
||||
{
|
||||
sleep(LONGTIME);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
handler(int sig)
|
||||
{
|
||||
/*
|
||||
* Nothing to do; invoking the handler is enough to interrupt
|
||||
* the sleep.
|
||||
*/
|
||||
}
|
Loading…
Reference in New Issue
Block a user