Skip to content

Commit a86c329

Browse files
committed
Change getpid() while loop to use sched_yield(), greatly speeds up test.
sched_yield is a requirement for the test but not for our PostgreSQL code, so if it causes a portability problem, we will remove it.
1 parent 49c8d08 commit a86c329

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/tools/thread/thread_test.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/tools/thread/thread_test.c,v 1.13 2004/04/05 05:43:06 momjian Exp $
9+
* $PostgreSQL: pgsql/src/tools/thread/thread_test.c,v 1.14 2004/04/05 14:12:32 momjian Exp $
1010
*
1111
* This program tests to see if your standard libc functions use
1212
* pthread_setspecific()/pthread_getspecific() to be thread-safe.
@@ -83,7 +83,7 @@ defines to your template/$port file before compiling this program.\n\n"
8383
pthread_create(&thread2, NULL, (void * (*)(void *)) func_call_2, NULL);
8484

8585
while (thread1_done == 0 || thread2_done == 0)
86-
getpid(); /* force system call */
86+
sched_yield(); /* force system call */
8787

8888
printf("Add this to your template/$port file:\n\n");
8989

@@ -129,7 +129,7 @@ void func_call_1(void) {
129129
*/
130130
errno1_set = 1;
131131
while (errno2_set == 0)
132-
getpid(); /* force system call */
132+
sched_yield(); /* force system call */
133133
if (errno != EEXIST)
134134
{
135135
fprintf(stderr, "errno not thread-safe; exiting\n");
@@ -184,7 +184,7 @@ void func_call_2(void) {
184184
*/
185185
errno2_set = 1;
186186
while (errno1_set == 0)
187-
getpid(); /* force system call */
187+
sched_yield(); /* force system call */
188188
if (errno != ENOENT)
189189
{
190190
fprintf(stderr, "errno not thread-safe; exiting\n");

0 commit comments

Comments
 (0)