Curl appears to be not thread safe so only have one curl open at a time.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
diff --git a/cpu-miner.c b/cpu-miner.c
index edd0616..131495a 100644
--- a/cpu-miner.c
+++ b/cpu-miner.c
@@ -143,6 +143,7 @@ int longpoll_thr_id;
struct work_restart *work_restart = NULL;
pthread_mutex_t time_lock;
static pthread_mutex_t hash_lock;
+static pthread_mutex_t submit_lock;
static pthread_mutex_t get_lock;
static double total_mhashes_done;
static struct timeval total_tv_start, total_tv_end;
@@ -467,6 +468,9 @@ static void *submit_thread(void *userdata)
int failures = 0;
CURL *curl;
+ /* libcurl seems to be not thread safe so only submit one at a time! */
+ pthread_mutex_lock(&submit_lock);
+
curl = curl_easy_init();
if (unlikely(!curl)) {
applog(LOG_ERR, "CURL initialization failed");
@@ -490,6 +494,7 @@ static void *submit_thread(void *userdata)
free(hexstr);
curl_easy_cleanup(curl);
+ pthread_mutex_unlock(&submit_lock);
return NULL;
}
@@ -1300,6 +1305,8 @@ int main (int argc, char *argv[])
return 1;
if (unlikely(pthread_mutex_init(&hash_lock, NULL)))
return 1;
+ if (unlikely(pthread_mutex_init(&submit_lock, NULL)))
+ return 1;
if (unlikely(pthread_mutex_init(&get_lock, NULL)))
return 1;