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
4cc247f7
Commit
4cc247f7
authored
21 years ago
by
Bruce Momjian
Browse files
Options
Downloads
Patches
Plain Diff
Add test for thread-safeness of libc functions.
parent
c351729e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/port/thread.c
+3
-1
3 additions, 1 deletion
src/port/thread.c
src/tools/test_thread_funcs.c
+126
-0
126 additions, 0 deletions
src/tools/test_thread_funcs.c
with
129 additions
and
1 deletion
src/port/thread.c
+
3
−
1
View file @
4cc247f7
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
*
*
* $Id: thread.c,v 1.
4
2003/0
8/16
1
5
:3
5:5
1 momjian Exp $
* $Id: thread.c,v 1.
5
2003/0
9/03
1
9
:3
0:3
1 momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -39,6 +39,8 @@
...
@@ -39,6 +39,8 @@
* The current setup is to assume either all standard functions are
* The current setup is to assume either all standard functions are
* thread-safe (NEED_REENTRANT_FUNC_NAMES=no), or the operating system
* thread-safe (NEED_REENTRANT_FUNC_NAMES=no), or the operating system
* requires reentrant function names (NEED_REENTRANT_FUNC_NAMES=yes).
* requires reentrant function names (NEED_REENTRANT_FUNC_NAMES=yes).
* Compile and run src/tools/test_thread_funcs.c to see if your operating
* system requires reentrant function names.
*/
*/
...
...
This diff is collapsed.
Click to expand it.
src/tools/test_thread_funcs.c
0 → 100644
+
126
−
0
View file @
4cc247f7
/*-------------------------------------------------------------------------
*
* test_thread_funcs.c
* libc thread test program
*
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/tools/Attic/test_thread_funcs.c,v 1.1 2003/09/03 19:30:31 momjian Exp $
*
* This program tests to see if your standard libc functions use
* pthread_setspecific()/pthread_getspecific() to be thread-safe.
* See src/port/thread.c for more details.
*
* This program first tests to see if each function returns a constant
* memory pointer within the same thread, then, assuming it does, tests
* to see if the pointers are different for different threads. If they
* are, the function is thread-safe.
*
* This program must be compiled with the thread flags required by your
* operating system. See src/template for the appropriate flags, if any.
*
*-------------------------------------------------------------------------
*/
#include
<pthread.h>
#include
<unistd.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<netdb.h>
#include
<sys/types.h>
#include
<pwd.h>
#include
<string.h>
#include
<errno.h>
void
func_call_1
(
void
);
void
func_call_2
(
void
);
struct
hostent
*
hostent_p1
;
struct
hostent
*
hostent_p2
;
struct
passwd
*
passwd_p1
;
struct
passwd
*
passwd_p2
;
char
*
strerror_p1
;
char
*
strerror_p2
;
int
main
(
int
argc
,
char
*
argv
[])
{
pthread_t
thread1
,
thread2
;
if
(
argc
>
1
)
{
fprintf
(
stderr
,
"Usage: %s
\n
"
,
argv
[
0
]);
return
1
;
}
pthread_create
(
&
thread1
,
NULL
,
(
void
*
)
func_call_1
,
NULL
);
pthread_create
(
&
thread2
,
NULL
,
(
void
*
)
func_call_2
,
NULL
);
pthread_join
(
thread1
,
NULL
);
pthread_join
(
thread2
,
NULL
);
if
(
hostent_p1
!=
hostent_p2
&&
passwd_p1
!=
passwd_p2
&&
strerror_p1
!=
strerror_p2
)
printf
(
"Your functions are all thread-safe
\n
"
);
else
printf
(
"Your functions are _not_ all thread-safe
\n
"
);
return
0
;
}
void
func_call_1
(
void
)
{
void
*
p
;
hostent_p1
=
gethostbyname
(
"yahoo.com"
);
p
=
gethostbyname
(
"slashdot.org"
);
if
(
hostent_p1
!=
p
)
{
printf
(
"Your gethostbyname() changes the static memory area between calls
\n
"
);
hostent_p1
=
NULL
;
/* force thread-safe failure report */
}
passwd_p1
=
getpwuid
(
0
);
p
=
getpwuid
(
1
);
if
(
passwd_p1
!=
p
)
{
printf
(
"Your getpwuid() changes the static memory area between calls
\n
"
);
passwd_p1
=
NULL
;
/* force thread-safe failure report */
}
strerror_p1
=
strerror
(
EACCES
);
/*
* If strerror() uses sys_errlist, the pointer might change for different
* errno values, so we don't check to see if it varies within the thread.
*/
}
void
func_call_2
(
void
)
{
void
*
p
;
hostent_p2
=
gethostbyname
(
"google.com"
);
p
=
gethostbyname
(
"postgresql.org"
);
if
(
hostent_p2
!=
p
)
{
printf
(
"Your gethostbyname() changes the static memory area between calls
\n
"
);
hostent_p2
=
NULL
;
/* force thread-safe failure report */
}
passwd_p2
=
getpwuid
(
2
);
p
=
getpwuid
(
3
);
if
(
passwd_p2
!=
p
)
{
printf
(
"Your getpwuid() changes the static memory area between calls
\n
"
);
passwd_p2
=
NULL
;
/* force thread-safe failure report */
}
strerror_p2
=
strerror
(
EINVAL
);
/*
* If strerror() uses sys_errlist, the pointer might change for different
* errno values, so we don't check to see if it varies within the thread.
*/
}
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