c - Is getaddrinfo_a thread safe? -
i want use getaddrinfo_a function. method thread safe? in man page example given uses global list resolving hostnames. if manipulate list in user space safe? pseudo-code follows:
static struct gaicb **reqs =null; // global list of hostname resolve. addtolist() { ret = getaddrinfo_a( gai_nowait, &reqs[nreqs_base], nreqs - nreqs_base, null ); // enque hostname queue. } //another thread method dequeu_list( int ) { struct gaicb * result = reqs[i] ; reqs[i] = null; }
yes, see in source code:
... int getaddrinfo_a (int mode, struct gaicb *list[], int ent, struct sigevent *sig) { ... no acess list ... /* request mutex. */ pthread_mutex_lock (&__gai_requests_mutex); /* can enqueue requests. since acquired mutex enqueue function need not this. */ (cnt = 0; cnt < ent; ++cnt) if (list[cnt] != null) { ...
it acquires mutex before accessing list
.
anyway it's similar getaddrinfo
required thread-safe:
the
freeaddrinfo()
,getaddrinfo()
functions shall thread-safe.
Comments
Post a Comment