Subject: About thread safety

About thread safety

From: Eino Tuominen <eino_at_utu.fi>
Date: Wed, 21 May 2008 17:53:26 +0300

Hi,

I tried to read through the docs but didn't see this one mentioned: can
is it safe to call e.g. ares_gethostbyname() using channel initialized
on another thread? Basically I want to do this on a multithreaded app
(c-ish pseudocode):

Thread A:

ares_init(channel);

for (;;) {
        select();
        ares_process();

Thread B (and others):

ares_gethostbyname(channel, ...);

In preliminary tests I have found this working well, I just want to make
sure I'm not doing anything overly stupid. Idea is to have just one (or
a few if the server is something like Sun T2000) ares instance and pass
the results from callback function to the other thread. If this is not
safe, can I just protect calls to ares_* functions with mutexes? If yes,
which functions must be protected?

Or, do I have to pass the request over to the thread that initialized
the channel and have it call ares_gethostbyname().

-- 
   Eino Tuominen
	
Received on 2008-05-21