Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
a1d63d92
Commit
a1d63d92
authored
20 years ago
by
Bruce Momjian
Browse files
Options
Downloads
Patches
Plain Diff
Have threads wait for parent to test thread-specific pointers before
exiting.
parent
422d4819
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/tools/thread/thread_test.c
+36
-8
36 additions, 8 deletions
src/tools/thread/thread_test.c
with
36 additions
and
8 deletions
src/tools/thread/thread_test.c
+
36
−
8
View file @
a1d63d92
...
...
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/tools/thread/thread_test.c,v 1.1
2
2004/04/05 0
2:22:14
momjian Exp $
* $PostgreSQL: pgsql/src/tools/thread/thread_test.c,v 1.1
3
2004/04/05 0
5:43:06
momjian Exp $
*
* This program tests to see if your standard libc functions use
* pthread_setspecific()/pthread_getspecific() to be thread-safe.
...
...
@@ -40,6 +40,9 @@ char myhostname[MAXHOSTNAMELEN];
volatile
int
errno1_set
=
0
;
volatile
int
errno2_set
=
0
;
volatile
int
thread1_done
=
0
;
volatile
int
thread2_done
=
0
;
char
*
strerror_p1
;
char
*
strerror_p2
;
...
...
@@ -49,9 +52,8 @@ struct passwd *passwd_p2;
struct
hostent
*
hostent_p1
;
struct
hostent
*
hostent_p2
;
pthread_mutex_t
singlethread_lock1
=
PTHREAD_MUTEX_INITIALIZER
;
pthread_mutex_t
singlethread_lock2
=
PTHREAD_MUTEX_INITIALIZER
;
pthread_mutex_t
init_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
int
main
(
int
argc
,
char
*
argv
[])
{
pthread_t
thread1
,
...
...
@@ -73,10 +75,15 @@ int main(int argc, char *argv[])
Make sure you have added any needed 'THREAD_CPPFLAGS' and 'THREAD_LIBS'
\n
\
defines to your template/$port file before compiling this program.
\n\n
"
);
/* Hold lock until we are ready for the child threads to exit. */
pthread_mutex_lock
(
&
init_mutex
);
pthread_create
(
&
thread1
,
NULL
,
(
void
*
(
*
)(
void
*
))
func_call_1
,
NULL
);
pthread_create
(
&
thread2
,
NULL
,
(
void
*
(
*
)(
void
*
))
func_call_2
,
NULL
);
pthread_join
(
thread1
,
NULL
);
pthread_join
(
thread2
,
NULL
);
while
(
thread1_done
==
0
||
thread2_done
==
0
)
getpid
();
/* force system call */
printf
(
"Add this to your template/$port file:
\n\n
"
);
...
...
@@ -94,7 +101,12 @@ defines to your template/$port file before compiling this program.\n\n"
printf
(
"GETHOSTBYNAME_THREADSAFE=yes
\n
"
);
else
printf
(
"GETHOSTBYNAME_THREADSAFE=no
\n
"
);
pthread_mutex_unlock
(
&
init_mutex
);
/* let children exit */
pthread_join
(
thread1
,
NULL
);
/* clean up children */
pthread_join
(
thread2
,
NULL
);
return
0
;
}
...
...
@@ -110,7 +122,11 @@ void func_call_1(void) {
fprintf
(
stderr
,
"could not generate failure for create file in /tmp, exiting
\n
"
);
exit
(
1
);
}
/* wait for other thread to set errno */
/*
* Wait for other thread to set errno.
* We can't use thread-specific locking here because it might
* affect errno.
*/
errno1_set
=
1
;
while
(
errno2_set
==
0
)
getpid
();
/* force system call */
...
...
@@ -144,6 +160,10 @@ void func_call_1(void) {
printf
(
"Your gethostbyname() changes the static memory area between calls
\n
"
);
hostent_p1
=
NULL
;
/* force thread-safe failure report */
}
thread1_done
=
1
;
pthread_mutex_lock
(
&
init_mutex
);
/* wait for parent to test */
pthread_mutex_unlock
(
&
init_mutex
);
}
...
...
@@ -157,7 +177,11 @@ void func_call_2(void) {
fprintf
(
stderr
,
"Read-only open succeeded without create, exiting
\n
"
);
exit
(
1
);
}
/* wait for other thread to set errno */
/*
* Wait for other thread to set errno.
* We can't use thread-specific locking here because it might
* affect errno.
*/
errno2_set
=
1
;
while
(
errno1_set
==
0
)
getpid
();
/* force system call */
...
...
@@ -191,4 +215,8 @@ void func_call_2(void) {
printf
(
"Your gethostbyname() changes the static memory area between calls
\n
"
);
hostent_p2
=
NULL
;
/* force thread-safe failure report */
}
thread2_done
=
1
;
pthread_mutex_lock
(
&
init_mutex
);
/* wait for parent to test */
pthread_mutex_unlock
(
&
init_mutex
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment