cURL / Mailing Lists / curl-library / Single Mail



From: Giuseppe Attardi <>
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 ORIGINAL
/* Beware this is a global and unique instance */
sigjmp_buf curl_jmpenv;
# else
extern pthread_key_t curl_jmpenv;
# endif

and then in Curl_resolv:

  /* 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;

Similarly, in url.c:

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

Each thread using cURL must issue this at startup:

  // 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 email is sponsored by:ThinkGeek
Welcome to geek heaven.
Received on 2003-09-17