arm-linux-gnueabi libcurl多线程上的分段错误

时间:2018-11-15 09:16:11

标签: c arm libcurl

在运行此示例时,我一直遇到细分错误 https://curl.haxx.se/libcurl/c/multithread.html

#include <stdio.h>
#include <pthread.h>
#include <curl/curl.h>

#define NUMT 4

const char * const urls[NUMT]= {
  "https://curl.haxx.se/",
  "ftp://cool.haxx.se/",
  "https://www.cag.se/",
  "www.haxx.se"
};

static void *pull_one_url(void *url)
{
  CURL *curl;

  curl = curl_easy_init();
  curl_easy_setopt(curl, CURLOPT_URL, url);
  curl_easy_perform(curl); /* ignores error */ 
  curl_easy_cleanup(curl);

  return NULL;
}

int main(int argc, char **argv)
{
  pthread_t tid[NUMT];
  int i;
  int error;

  /* Must initialize libcurl before any threads are started */ 
  curl_global_init(CURL_GLOBAL_ALL);

  for(i = 0; i< NUMT; i++) {
    error = pthread_create(&tid[i],
                           NULL, /* default attributes please */ 
                           pull_one_url,
                           (void *)urls[i]);
    if(0 != error)
      fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error);
    else
      fprintf(stderr, "Thread %d, gets %s\n", i, urls[i]);
  }

  /* now wait for all threads to terminate */ 
  for(i = 0; i< NUMT; i++) {
    error = pthread_join(tid[i], NULL);
    fprintf(stderr, "Thread %d terminated\n", i);
  }

  return 0;
}

我用arm-none-linux-gnueabi-gcc交叉编译器在Ubuntu 14.04上交叉编译了代码。

而且,我正在使用(静态链接):

  • libcurl(curl-7.38.0)
  • openssl(1.0.1u)

错误消息:

 Connected to cool.haxx.se (80.67.6.50) port 21 (#0)
* response reading failed
* Closing connection 0
Segmentation fault (core dumped)

curl()调用来自单个线程时,它工作正常,但是当我尝试从多个线程中调用curl()时,它将引发错误。

0 个答案:

没有答案