svn commit: r291421 - in user/pho/stress2: misc testcases/thr1 testcases/thr2
Peter Holm
pho at FreeBSD.org
Sat Nov 28 09:34:48 UTC 2015
Author: pho
Date: Sat Nov 28 09:34:45 2015
New Revision: 291421
URL: https://svnweb.freebsd.org/changeset/base/291421
Log:
Fix pthread error handling.
Sponsored by: EMC / Isilon storage division
Modified:
user/pho/stress2/misc/db.sh
user/pho/stress2/misc/devfd.sh
user/pho/stress2/misc/devfs2.sh
user/pho/stress2/misc/f_offset.sh
user/pho/stress2/misc/kevent2.sh
user/pho/stress2/misc/kinfo3.sh
user/pho/stress2/misc/mmap2.sh
user/pho/stress2/misc/mmap3.sh
user/pho/stress2/misc/pthread5.sh
user/pho/stress2/misc/pthread9.sh
user/pho/stress2/misc/truss.sh
user/pho/stress2/testcases/thr1/thr1.c
user/pho/stress2/testcases/thr2/thr2.c
Modified: user/pho/stress2/misc/db.sh
==============================================================================
--- user/pho/stress2/misc/db.sh Sat Nov 28 08:49:07 2015 (r291420)
+++ user/pho/stress2/misc/db.sh Sat Nov 28 09:34:45 2015 (r291421)
@@ -40,7 +40,6 @@ mycc -o db -Wall -Wextra -O0 -g db.c -lp
rm -f db.c
cd $odir
-diskimage=/var/tmp/diskimage
dd if=/dev/zero of=$diskimage bs=1m count=10 2>&1 | \
egrep -v "records|transferred"
@@ -89,16 +88,17 @@ wt(void *arg __unused)
time_t start;
int64_t pos;
void *c;
+ int r;
char buf[BZ];
#ifdef __NP__
pthread_set_name_np(pthread_self(), __func__);
#endif
- if (pthread_mutex_lock(&mutex) == -1)
- err(1, "pthread_mutex_lock");
+ if ((r = pthread_mutex_lock(&mutex)) != 0)
+ errc(1, r, "pthread_mutex_lock");
wthreads++;
- if (pthread_mutex_unlock(&mutex) == -1)
- err(1, "pthread_mutex_unlock");
+ if ((r = pthread_mutex_unlock(&mutex)) != 0)
+ errc(1, r, "pthread_mutex_unlock");
start = time(NULL);
while (time(NULL) - start < RUNTIME) {
@@ -112,11 +112,11 @@ wt(void *arg __unused)
usleep(10000 + arc4random() % 1000);
}
- if (pthread_mutex_lock(&mutex) == -1)
- err(1, "pthread_mutex_lock");
+ if ((r = pthread_mutex_lock(&mutex)) != 0)
+ errc(1, r, "pthread_mutex_lock");
wthreads--;
- if (pthread_mutex_unlock(&mutex) == -1)
- err(1, "pthread_mutex_unlock");
+ if ((r = pthread_mutex_unlock(&mutex)) != 0)
+ errc(1, r, "pthread_mutex_unlock");
return (NULL);
}
Modified: user/pho/stress2/misc/devfd.sh
==============================================================================
--- user/pho/stress2/misc/devfd.sh Sat Nov 28 08:49:07 2015 (r291420)
+++ user/pho/stress2/misc/devfd.sh Sat Nov 28 09:34:45 2015 (r291421)
@@ -115,14 +115,15 @@ int
main(void)
{
pthread_t p1, p2;
+ int r;
close(0);
close(1);
close(2);
- if (pthread_create(&p1, NULL, thr1, NULL) != 0)
- err(1, "pthread_create");
- if (pthread_create(&p2, NULL, thr2, NULL) != 0)
- err(1, "pthread_create");
+ if ((r = pthread_create(&p1, NULL, thr1, NULL)) != 0)
+ errc(1, r, "pthread_create");
+ if ((r = pthread_create(&p2, NULL, thr2, NULL)) != 0)
+ errc(1, r, "pthread_create");
pthread_join(p1, NULL);
pthread_join(p2, NULL);
Modified: user/pho/stress2/misc/devfs2.sh
==============================================================================
--- user/pho/stress2/misc/devfs2.sh Sat Nov 28 08:49:07 2015 (r291420)
+++ user/pho/stress2/misc/devfs2.sh Sat Nov 28 09:34:45 2015 (r291421)
@@ -103,8 +103,8 @@ main()
err(1, "pthread_create(): %s\n", strerror(r));
for (i = 0; i < 2; i++)
- if (pthread_join(threads[i], NULL) != 0)
- err(1, "pthread_join(%d)", i);
+ if ((r = pthread_join(threads[i], NULL)) != 0)
+ errc(1, r, "pthread_join(%d)", i);
return (0);
}
Modified: user/pho/stress2/misc/f_offset.sh
==============================================================================
--- user/pho/stress2/misc/f_offset.sh Sat Nov 28 08:49:07 2015 (r291420)
+++ user/pho/stress2/misc/f_offset.sh Sat Nov 28 09:34:45 2015 (r291421)
@@ -141,18 +141,18 @@ main(void)
for (i = 0; i < 20 && errors < 10; i++) {
if ((r = pthread_create(&threads[0], NULL, t1, 0)) != 0)
- err(1, "pthread_create(): %s\n", strerror(r));
+ errc(1, r, "pthread_create()");
if ((r = pthread_create(&threads[1], NULL, t2, 0)) != 0)
- err(1, "pthread_create(): %s\n", strerror(r));
+ errc(1, r, "pthread_create()");
if ((r = pthread_create(&threads[2], NULL, t3, 0)) != 0)
- err(1, "pthread_create(): %s\n", strerror(r));
+ errc(1, r, "pthread_create()");
- if (pthread_join(threads[0], NULL) != 0)
- err(1, "pthread_join(%d)", 0);
- if (pthread_join(threads[1], NULL) != 0)
- err(1, "pthread_join(%d)", 1);
- if (pthread_join(threads[2], NULL) != 0)
- err(1, "pthread_join(%d)", 2);
+ if ((r = pthread_join(threads[0], NULL)) != 0)
+ errc(1, r, "pthread_join(%d)", 0);
+ if ((r = pthread_join(threads[1], NULL)) != 0)
+ errc(1, r, "pthread_join(%d)", 1);
+ if ((r = pthread_join(threads[2], NULL)) != 0)
+ errc(1, r, "pthread_join(%d)", 2);
}
close(fd);
if (unlink(file) == -1)
Modified: user/pho/stress2/misc/kevent2.sh
==============================================================================
--- user/pho/stress2/misc/kevent2.sh Sat Nov 28 08:49:07 2015 (r291420)
+++ user/pho/stress2/misc/kevent2.sh Sat Nov 28 09:34:45 2015 (r291421)
@@ -42,9 +42,7 @@ for i in `jot 10`; do
for j in `jot 12`; do
/tmp/kevent2 > /dev/null 2>&1 &
done
- for j in `jot 12`; do
- wait
- done
+ wait
done
rm -f /tmp/kevent2
exit
@@ -70,7 +68,7 @@ static int fd3[2];
void *
thr1(void *arg)
{
- int n;
+ int n, r;
int kq = -1;
struct kevent ev[3];
struct timespec ts;
@@ -92,13 +90,13 @@ thr1(void *arg)
if (kevent(kq, ev, n, NULL, 0, NULL) < 0)
err(1, "kevent(). %s:%d", __FILE__, __LINE__);
- if (pthread_mutex_lock(&mutex) == -1)
- err(1, "pthread_mutex_lock");
+ if ((r = pthread_mutex_lock(&mutex)) != 0)
+ errc(1, r, "pthread_mutex_lock");
waiting = 0;
- if (pthread_cond_signal(&cond) == -1)
- err(1, "pthread_cond_signal");
- if (pthread_mutex_unlock(&mutex) == -1)
- err(1, "pthread_mutex_unlock");
+ if ((r = pthread_cond_signal(&cond)) != 0)
+ errc(1, r, "pthread_cond_signal");
+ if ((r = pthread_mutex_unlock(&mutex)) != 0)
+ errc(1, r, "pthread_mutex_unlock");
n = 0;
EV_SET(&ev[n], fd1[1], EVFILT_WRITE,
@@ -120,14 +118,16 @@ thr1(void *arg)
void *
thr2(void *arg)
{
- if (pthread_mutex_lock(&mutex) == -1)
- err(1, "pthread_mutex_lock");
+ int r;
+
+ if ((r = pthread_mutex_lock(&mutex)) != 0)
+ errc(1, r, "pthread_mutex_lock");
while (waiting == 1) {
- if (pthread_cond_wait(&cond, &mutex) == -1)
- err(1, "pthread_cond_wait");
+ if ((r = pthread_cond_wait(&cond, &mutex)) != 0)
+ errc(1, r, "pthread_cond_wait");
}
- if (pthread_mutex_unlock(&mutex) == -1)
- err(1, "pthread_mutex_unlock");
+ if ((r = pthread_mutex_unlock(&mutex)) != 0)
+ errc(1, r, "pthread_mutex_unlock");
// printf("%s:%d\n", __FILE__, __LINE__); fflush(stdout);
close(fd1[0]);
close(fd2[0]);
@@ -152,24 +152,24 @@ main(int argc, char **argv)
if (pipe(fd3) == -1)
err(1, "pipe()");
- if (pthread_mutex_init(&mutex, 0) == -1)
- err(1, "pthread_mutex_init");
- if (pthread_cond_init(&cond, NULL) == -1)
- err(1, "pthread_cond_init");
+ if ((r = pthread_mutex_init(&mutex, 0)) != 0)
+ errc(1, r, "pthread_mutex_init");
+ if ((r = pthread_cond_init(&cond, NULL)) != 0)
+ errc(1, r, "pthread_cond_init");
if ((r = pthread_create(&threads[0], NULL, thr1, 0)) != 0)
- err(1, "pthread_create(): %s\n", strerror(r));
+ errc(1, r, "pthread_create()");
if ((r = pthread_create(&threads[1], NULL, thr2, 0)) != 0)
- err(1, "pthread_create(): %s\n", strerror(r));
+ errc(1, r, "pthread_create()");
- if (pthread_join(threads[0], NULL) != 0)
- err(1, "pthread_join(%d)", 0);
- if (pthread_join(threads[1], NULL) != 0)
- err(1, "pthread_join(%d)", 1);
- if (pthread_mutex_destroy(&mutex) == -1)
- err(1, "pthread_mutex_destroy");
- if (pthread_cond_destroy(&cond) == -1)
- err(1, "pthread_condattr_destroy");
+ if ((r = pthread_join(threads[0], NULL)) != 0)
+ errc(1, r, "pthread_join(%d)", 0);
+ if ((r = pthread_join(threads[1], NULL)) != 0)
+ errc(1, r, "pthread_join(%d)", 1);
+ if ((r = pthread_mutex_destroy(&mutex)) != 0)
+ errc(1, r, "pthread_mutex_destroy");
+ if ((r = pthread_cond_destroy(&cond)) != 0)
+ errc(1, r, "pthread_condattr_destroy");
}
return (0);
Modified: user/pho/stress2/misc/kinfo3.sh
==============================================================================
--- user/pho/stress2/misc/kinfo3.sh Sat Nov 28 08:49:07 2015 (r291420)
+++ user/pho/stress2/misc/kinfo3.sh Sat Nov 28 09:34:45 2015 (r291421)
@@ -104,11 +104,11 @@ churning(void) {
if (r == 0) {
for (i = 0; i < 5; i++) {
if ((r = pthread_create(&threads[i], NULL, thr, 0)) != 0)
- err(1, "pthread_create(): %s\n", strerror(r));
+ errc(1, r, "pthread_create()");
}
for (i = 0; i < 5; i++) {
- if (pthread_join(threads[i], NULL) != 0)
- err(1, "pthread_join(%d)", 0);
+ if ((r = pthread_join(threads[i], NULL)) != 0)
+ errc(1, r, "pthread_join(%d)", i);
}
bzero(buf, sizeof(buf));
Modified: user/pho/stress2/misc/mmap2.sh
==============================================================================
--- user/pho/stress2/misc/mmap2.sh Sat Nov 28 08:49:07 2015 (r291420)
+++ user/pho/stress2/misc/mmap2.sh Sat Nov 28 09:34:45 2015 (r291421)
@@ -41,7 +41,8 @@ sed '1,/^EOF/d' < $odir/$0 > mmap2.c
mycc -o mmap2 -Wall -g mmap2.c -lpthread
rm -f mmap2.c
-for i in `jot 10`; do
+start=`date '+%s'`
+while [ $((`date '+%s'` - start)) -lt 600 ]; do
./mmap2
done
rm -f ./mmap2
@@ -166,12 +167,12 @@ main(int argc, char **argv)
for (i = 0; i < n; i++) {
nr[i] = i;
if ((r = pthread_create(&threads[i], NULL, thr, (void *)&nr[i])) != 0)
- err(1, "pthread_create(): %s\n", strerror(r));
+ errc(1, r, "pthread_create()");
}
for (i = 0; i < n; i++) {
- if (pthread_join(threads[i], NULL) != 0)
- err(1, "pthread_join(%d)", i);
+ if ((r = pthread_join(threads[i], NULL)) != 0)
+ errc(1, r, "pthread_join(%d)", i);
}
return (0);
Modified: user/pho/stress2/misc/mmap3.sh
==============================================================================
--- user/pho/stress2/misc/mmap3.sh Sat Nov 28 08:49:07 2015 (r291420)
+++ user/pho/stress2/misc/mmap3.sh Sat Nov 28 09:34:45 2015 (r291421)
@@ -157,12 +157,12 @@ main(int argc, char **argv)
for (i = 0; i < n; i++) {
nr[i] = i;
if ((r = pthread_create(&threads[i], NULL, thr, (void *)&nr[i])) != 0)
- err(1, "pthread_create(): %s\n", strerror(r));
+ errc(1, r, "pthread_create()");
}
for (i = 0; i < n; i++) {
- if (pthread_join(threads[i], NULL) != 0)
- err(1, "pthread_join(%d)", i);
+ if ((r = pthread_join(threads[i], NULL)) != 0)
+ errc(1, r, "pthread_join(%d)", i);
}
return (0);
Modified: user/pho/stress2/misc/pthread5.sh
==============================================================================
--- user/pho/stress2/misc/pthread5.sh Sat Nov 28 08:49:07 2015 (r291420)
+++ user/pho/stress2/misc/pthread5.sh Sat Nov 28 09:34:45 2015 (r291421)
@@ -91,7 +91,7 @@ test(void)
for (iter = 0; iter < ITER; iter++) {
for (i = 0; i < num_thread; i++) {
if ((rc = pthread_create(&tid[i], NULL, nicethreads,
- NULL)) == -1)
+ NULL)) != 0)
errc(1, rc, "pthread_create");
}
usleep(20000);
@@ -101,7 +101,7 @@ test(void)
rc = pthread_mutex_unlock(&mutex);
}
for (i = 0; i < num_thread; i++)
- if ((rc = pthread_join(tid[i], NULL)) == -1)
+ if ((rc = pthread_join(tid[i], NULL)) != 0)
errc(1, rc, "pthread_join");
}
Modified: user/pho/stress2/misc/pthread9.sh
==============================================================================
--- user/pho/stress2/misc/pthread9.sh Sat Nov 28 08:49:07 2015 (r291420)
+++ user/pho/stress2/misc/pthread9.sh Sat Nov 28 09:34:45 2015 (r291421)
@@ -147,17 +147,17 @@ test(void)
int i, rc;
go = 0;
- if ((rc = pthread_create(&tid[0], NULL, t1, NULL)) == -1)
+ if ((rc = pthread_create(&tid[0], NULL, t1, NULL)) != 0)
errc(1, rc, "pthread_create");
- if ((rc = pthread_create(&tid[1], NULL, t2, NULL)) == -1)
+ if ((rc = pthread_create(&tid[1], NULL, t2, NULL)) != 0)
errc(1, rc, "pthread_create");
- if ((rc = pthread_create(&tid[2], NULL, t3, NULL)) == -1)
+ if ((rc = pthread_create(&tid[2], NULL, t3, NULL)) != 0)
errc(1, rc, "pthread_create");
usleep(200);
atomic_add_int(&go, 1);
for (i = 0; i < 3; i++) {
- if ((rc = pthread_join(tid[i], NULL)) == -1)
+ if ((rc = pthread_join(tid[i], NULL)) != 0)
errc(1, rc, "pthread_join");
}
Modified: user/pho/stress2/misc/truss.sh
==============================================================================
--- user/pho/stress2/misc/truss.sh Sat Nov 28 08:49:07 2015 (r291420)
+++ user/pho/stress2/misc/truss.sh Sat Nov 28 09:34:45 2015 (r291421)
@@ -115,13 +115,13 @@ main(int argc, char *argv[])
start = time(NULL);
while ((time(NULL) - start) < runtime) {
for (i = 0; i < THREADS; i++) {
- if ((rc = pthread_create(&tid[i], NULL, t1, NULL)) ==
- -1)
+ if ((rc = pthread_create(&tid[i], NULL, t1, NULL)) !=
+ 0)
errc(1, rc, "pthread_create");
}
for (i = 0; i < THREADS; i++) {
- if ((rc = pthread_join(tid[i], NULL)) == -1)
+ if ((rc = pthread_join(tid[i], NULL)) != 0)
errc(1, rc, "pthread_join");
}
}
Modified: user/pho/stress2/testcases/thr1/thr1.c
==============================================================================
--- user/pho/stress2/testcases/thr1/thr1.c Sat Nov 28 08:49:07 2015 (r291420)
+++ user/pho/stress2/testcases/thr1/thr1.c Sat Nov 28 09:34:45 2015 (r291421)
@@ -71,8 +71,8 @@ test(void)
err(1, "pthread_create(): %s\n", strerror(r));
for (i = 0; i < NTHREADS; i++)
- if (pthread_join(threads[i], NULL) != 0)
- err(1, "pthread_join(%d)", i);
+ if ((r = pthread_join(threads[i], NULL)) != 0)
+ errc(1, r, "pthread_join(%d)", i);
return (0);
}
Modified: user/pho/stress2/testcases/thr2/thr2.c
==============================================================================
--- user/pho/stress2/testcases/thr2/thr2.c Sat Nov 28 08:49:07 2015 (r291420)
+++ user/pho/stress2/testcases/thr2/thr2.c Sat Nov 28 09:34:45 2015 (r291421)
@@ -89,8 +89,8 @@ test(void)
done = 1;
for (i = 0; i < NTHREADS; i++)
- if (pthread_join(threads[i], NULL) != 0)
- err(1, "pthread_join(%d)", i);
+ if ((r = pthread_join(threads[i], NULL)) != 0)
+ errc(1, r, "pthread_join(%d)", i);
return (0);
}
More information about the svn-src-user
mailing list