Operating System - HP-UX
1834006 Members
1607 Online
110063 Solutions
New Discussion

gethostbyaddr & multi-thread

 
Michelle_61
Frequent Advisor

gethostbyaddr & multi-thread

Hello,

I want to know if gethostbyaddr (HPUX 11) is thread safe. If not, are there any other functions I can use?

Thanks
4 REPLIES 4
Steve Steel
Honored Contributor

Re: gethostbyaddr & multi-thread

Hi


libc threads -- Which calls are thread safe? Which are not?

RESOLUTION TEXT

Starting at 10.0, libc functions are safe for use in multi-threaded
applications.


Thus no problem


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Simon Hargrave
Honored Contributor

Re: gethostbyaddr & multi-thread

Looking at the manpage, it's thread safe but you have to take a little care with how you handle it: -

---

In a multithreaded application, gethostent(), gethostbyaddr(), and gethostbyname() use thread-specific storage that is re-used in each call. The return value, struct hostent, should be unique for each thread and should be saved, if desired, before the thread makes the next gethost*() call.

For enumeration in multithreaded applications, the position within the enumeration is a process-wide property shared by all threads. sethostent() may be used in a multithreaded application, but resets the enumeration position for all threads. If multiple threads interleave calls to gethostent(), the threads will enumerate disjoint subsets of the host database.

---
rick jones
Honored Contributor

Re: gethostbyaddr & multi-thread

If you are targetting HP-UX 11i (11.11) and later, you may want to use getnameinfo() and friends (getaddrinfo) instead since those are the routines that work for both IPv4 and IPv6.

There are also small open-source bits out there that will allow you to use those routines on 11.00 or other platforms without a native getaddrinfo() call. I use one in the 2.4.0 version of netperf - http://www.netperf.org/

I suspect the native getnodeinfo on 11.11 and later is thread-safe. I'm not sure if the package I use to emulate those for 11.0 is or not.
there is no rest for the wicked yet the virtuous have no pillows
Michelle_61
Frequent Advisor

Re: gethostbyaddr & multi-thread

Thanks for all the information.

Steve, if all libc functions are thread safe then why I see in page
http://docs.hp.com/en/B3921-90010/thread_safety.5.html there are still functions which are not thread-safe?

For example, setmntent is classfied in "Interfaces That Are Not thread-safe" category. I am quite concerned about this because I am using setmntent, getmntent and endmntent.