cURL / Mailing Lists / curl-library / Single Mail

curl-library

multithreading

From: Giuseppe Attardi <attardi_at_di.unipi.it>
Date: Wed, 17 Sep 2003 09:30:17 +0200

I have made a few simple changes to allow uses of
libcurl in a multithreading environment.
Let me know if this is a reasonable approach.

Changes assume the use of pthreads: suitable
OS specific macros should be defined to handle
other cases.

I have turned curl_jmpenv into a thread-specific variable,
rather than a single global variable.

In hostip.c:

#ifdef HAVE_SIGSETJMP
# ifdef ORIGINAL
/* Beware this is a global and unique instance */
sigjmp_buf curl_jmpenv;
# else
extern pthread_key_t curl_jmpenv;
# endif
#endif

and then in Curl_resolv:

#ifdef HAVE_SIGSETJMP
  /* this allows us to time-out from the name resolver, as the timeout
     will generate a signal and we will siglongjmp() from that here */
  if(!data->set.no_signal &&
# ifdef ORIGINAL
     sigsetjmp(curl_jmpenv, 1)
# else
     sigsetjmp((void*)pthread_getspecific(curl_jmpenv), 1)
# endif
     ) {
    /* this is coming from a siglongjmp() */
    failf(data, "name lookup timed out");
    return -1;
  }
#endif

Similarly, in url.c:

RETSIGTYPE alarmfunc(int signal)
{
  /* this is for "-ansi -Wall -pedantic" to stop complaining! (rabe) */
  (void)signal;
#ifdef HAVE_SIGSETJMP
# ifdef ORIGINAL
  siglongjmp(curl_jmpenv, 1);
# else
  siglongjmp((void*)pthread_getspecific(curl_jmpenv), 1);
# endif
#endif
  return;
}

Each thread using cURL must issue this at startup:

# ifdef HAVE_PTHREADS
  // create thread specific jmpbuf used by cUrl to handle
  // time-outs from the name resolver
  jmp_buf excption;

  pthread_setspecific(curl_jmpenv, (void*)excption);
# endif

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Received on 2003-09-17