Operating System - HP-UX
1833325 Members
3066 Online
110051 Solutions
New Discussion

gethostbyname thread safe?!

 
SOLVED
Go to solution
devshlom
Regular Advisor

gethostbyname thread safe?!

Hi,

I'm using the gethostbyname function in my code, which is compiled on different UNIXs (AIX,HP, Linux, Solaris, etc.)
I found in the web people that say that this function is thread safe on some OS versions (HPUX 11, AIX 5... )
I must confirm this issue, so...
1. I need to know if this function is a thread safe on HPUX and if so, what is the minmal version for this safety?!
2. I read in HP documentation (http://docs.hp.com/en/B3921-90010/thread_safety.5.html) - what is the meaning of "Cancel Safe"? since this function is under this criteria.

tx in advance,
Shlom
8 REPLIES 8
Steven Schweda
Honored Contributor

Re: gethostbyname thread safe?!

> (HPUX 11, AIX 5... )

HP-UX "11" is not a precise description of an
HP-UX version.

I know nothing, but, resorting to the
painfully obvious "man gethostbyname" on an
HP-UX 11.31 PA-RISC system, I pretty easily
found a section which begins:

In a multithreaded application, [...]

and which seems to provide all the
thread-related info _I_'d ever want.

If you don't have an HP-UX system where you
can do this, try:

http://www.testdrive.hp.com/

Systems are available back to HP-UX 11.11.
Dennis Handly
Acclaimed Contributor

Re: gethostbyname thread safe?!

>what is the meaning of "Cancel Safe"?

It means that if you use pthread_cancel, everything is predictable.
devshlom
Regular Advisor

Re: gethostbyname thread safe?!

Hi,

1. Risc 11.23
2. Dennis, I didn't understand your answer - can you give more details please?! Actually, if you have some source that says that gethostbyname is thread safe on HPUX 11.23 (or not...) it would be better.

tx again.
Dennis Handly
Acclaimed Contributor

Re: gethostbyname thread safe?!

>1. PA-RISC 11.23

Your 11.11 document says it is thread safe. So does 11.23:
http://docs.hp.com/en/B3921-60631/thread_safety.5.html

>2. I didn't understand your answer - can you give more details please?

It is thread safe. It is also non-asynchronous cancel safe.

>if you have some source that says that gethostbyname is thread safe on HPUX 11.23

You have the source, thread_safety(5).
And as Steven said see "multithreaded application" in gethostent(3N).
devshlom
Regular Advisor

Re: gethostbyname thread safe?!

Dennis,
tx again for giving me the answer - I understand now that this is a thread safe function.

Now, for my general info:
I still don't understand the meaning of "Cancel-Safe"...
If a function is Cancel-Safe one, so it's a ____________________________

shlom

Dennis Handly
Acclaimed Contributor
Solution

Re: gethostbyname thread safe?!

>I still don't understand the meaning of "Cancel-Safe".

See pthread_cancel(3T):
http://docs.hp.com/en/B2355-60130/pthread_cancel.3T.html

It means the thread can be terminated in a controlled manner and doesn't leave resources lying around and possibly leave mutexes locked.
devshlom
Regular Advisor

Re: gethostbyname thread safe?!

Tx!
rick jones
Honored Contributor

Re: gethostbyname thread safe?!

Now that you are confident that gethostbyname() is thread-safe and all, I will point-out that new work or contemporary rework of existing code should be using getaddrinfo() and friends rather than gethostbyname() :)

Among other things, getaddrinfo() enables retrieval of IPv6 addresses and can make a few things easier even with IPv4 addresses. At least that was my impression after making the necessary modifications to the netperf benchmark sources.
there is no rest for the wicked yet the virtuous have no pillows