Main Page | Report this Page
Linux Forum Index  »  Linux Development  »  Multithreaded socket
Page 1 of 1    

Multithreaded socket

Author Message
daniele_athome
Posted: Wed Apr 05, 2006 11:53 pm
Guest
Hi all! I have a problem with network host resolution in my multithreaded
application. Because of gethostbyname() which uses static data (i.e. is not
designed for multiple threads), I often have some "unexpected" results,
like this:

localhost 192.168.0.1
router 192.168.0.1

the second is right, the first not.
This happens if I make more than one resolution at a time.
One way could be locking the gethostbyname(), but until it will finish its
task, it won't exit and won't permit other thread to proceed with host
resolution...

What can I do without requiring external libraries? Or, if external
libraries are needed, can you suggest me any that is multithreaded?

thanks
--
daniele_athome
 
Scott Lacy Salley
Posted: Sun Apr 09, 2006 11:44 pm
Guest
In article <G02Zf.53150$nz4.41649@tornado.fastwebnet.it>, daniele_athome wrote:
Quote:
Hi all! I have a problem with network host resolution in my multithreaded
application. Because of gethostbyname() which uses static data (i.e. is not
designed for multiple threads), I often have some "unexpected" results,

gethostbyname_r

--
Scott Lacy Salley <scottlacysalley@comcast.net>
formerly Scott Lacy Smith
 
daniele_athome
Posted: Mon Apr 10, 2006 3:49 am
Guest
Scott Lacy Salley wrote:

Quote:
In article <G02Zf.53150$nz4.41649@tornado.fastwebnet.it>, daniele_athome
wrote:
Hi all! I have a problem with network host resolution in my multithreaded
application. Because of gethostbyname() which uses static data (i.e. is
not designed for multiple threads), I often have some "unexpected"
results,

gethostbyname_r


it doesn't work i'll use getaddrinfo
thanks anyway
bye Wink
--
daniele_athome
 
Scott Lacy Salley
Posted: Wed Apr 19, 2006 12:03 am
Guest
In article <8Sp_f.7166$QM3.4031@tornado.fastwebnet.it>, daniele_athome wrote:
Quote:
Scott Lacy Salley wrote:

In article <G02Zf.53150$nz4.41649@tornado.fastwebnet.it>, daniele_athome
wrote:
Hi all! I have a problem with network host resolution in my multithreaded
application. Because of gethostbyname() which uses static data (i.e. is
not designed for multiple threads), I often have some "unexpected"
results,

gethostbyname_r


it doesn't work i'll use getaddrinfo

Why or what doesn't work about it? Is it unavailable on your system or is
there a bug in it?

--
Scott Lacy Salley <scottlacysalley@comcast.net>
formerly Scott Lacy Smith
 
Steve Thompson
Posted: Thu Apr 20, 2006 3:45 pm
Guest
On Wed, 19 Apr 2006, Scott Lacy Salley wrote:

Quote:
In article <8Sp_f.7166$QM3.4031@tornado.fastwebnet.it>, daniele_athome wrote:
Scott Lacy Salley wrote:
In article <G02Zf.53150$nz4.41649@tornado.fastwebnet.it>,
daniele_athome wrote:
Hi all! I have a problem with network host resolution in my multithreaded
application. Because of gethostbyname() which uses static data (i.e. is
not designed for multiple threads), I often have some "unexpected"
results,

gethostbyname_r
it doesn't work i'll use getaddrinfo

Why or what doesn't work about it? Is it unavailable on your system or is
there a bug in it?

The problem is that gethostbyname() is not thread safe. If I have to use
it, and cannot use _r, I usually surround gethostbyname() by a mutex.

Steve
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Fri Mar 19, 2010 8:50 am