"www.example"
};
-static void *pull_one_url(void *pindex)
+struct targ {
+ const char *url;
+};
+
+
+static void *pull_one_url(void *p)
{
CURL *curl;
+ struct targ *targ = p;
curl = curl_easy_init();
if(curl) {
- int i = *(int *)pindex;
- curl_easy_setopt(curl, CURLOPT_URL, urls[i]);
+ curl_easy_setopt(curl, CURLOPT_URL, targ->url);
(void)curl_easy_perform(curl); /* ignores error */
curl_easy_cleanup(curl);
}
{
CURLcode res;
pthread_t tid[NUMT];
+ struct targ targs[NUMT];
int i;
/* Must initialize libcurl before any threads are started */
return (int)res;
for(i = 0; i < NUMT; i++) {
- int error = pthread_create(&tid[i],
- NULL, /* default attributes please */
- pull_one_url,
- (void *)&i);
+ int error;
+ targs[i].url = urls[i];
+ error = pthread_create(&tid[i],
+ NULL, /* default attributes please */
+ pull_one_url,
+ (void *)&targs[i]);
if(error)
fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error);
else