Is it multithreaded curl? one version of the curl i used was doing openssl_init and cleanup in its init and cleanup routines and it was not multithreaded. result was my code would not work properly if curl_cleanup is called before.
On Mon, Feb 27, 2012 at 7:52 PM, Anurag Shukla <[email protected]>wrote: > I am facing some random crash issues using libcurl with openssl in a Multi > threaded program. I wrote a sample code to create 2 threads that will ping > to https://www.google.com. > Using [libcurl- 7.21.7] [openssl- 1.0.0d] > > I have implemented the two callbacks function required by openssl > > #include <nspr.h> > #include "curl.h" > #include "openssl/crypto.h" > static PRRWLock *lockarray[CRYPTO_NUM_LOCKS]; > > static void ChangeLockStatus(int mode, int lock_index, const char* > file_name, int line_num) { > if (mode & CRYPTO_LOCK) { > if(mode & CRYPTO_WRITE) { > PR_RWLock_Wlock(lockarray[lock_index]); > } else if (mode & CRYPTO_READ) { > PR_RWLock_Rlock(lockarray[lock_index]); > } > } else { > PR_RWLock_Unlock(lockarray[lock_index]); > } > } > static unsigned long ID_Callback(void) { > unsigned long td = ::GetCurrentThreadId(); > return td; > } > static void Initialize() { > int i; > for (i = 0; i < CRYPTO_NUM_LOCKS; i++) { > lockarray[i] = PR_NewRWLock(PR_RWLOCK_RANK_NONE, "a"); > } > CRYPTO_set_locking_callback(ChangeLockStatus); > CRYPTO_set_id_callback(ID_Callback); > } > void Test(void *arg) { > int error_code; > FILE *fd = fopen("a.txt", "w"); > while(1) { > CURL * curl_connection = curl_easy_init(); > curl_easy_setopt(curl_connection, CURLOPT_TIMEOUT, 300); > curl_easy_setopt(curl_connection, CURLOPT_CONNECTTIMEOUT, 60); > curl_easy_setopt(curl_connection, CURLOPT_FOLLOWLOCATION, 1); > curl_easy_setopt(curl_connection, CURLOPT_VERBOSE, 0); > curl_easy_setopt(curl_connection, CURLOPT_SSL_VERIFYPEER, 0); > error_code = curl_easy_setopt(curl_connection, CURLOPT_PROXY, " > 192.168.1.1:8000"); > curl_easy_setopt(curl_connection, CURLOPT_FILE, fd); > curl_easy_setopt(curl_connection, CURLOPT_URL, " > https://www.google.com"); > error_code = curl_easy_perform(curl_connection); > curl_easy_cleanup(curl_connection); > Sleep(3000); > } > } > int main(int argc, char** argv) { > curl_global_init(CURL_GLOBAL_ALL); > Initialize(); > PRThread *threads[2]; > for(int i=0; i<2; i++) { > threads[i] = PR_CreateThread(PR_USER_THREAD, Test, NULL, > PR_PRIORITY_LOW, > PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 1024*10); > } > Sleep(3600000); > curl_global_cleanup(); > for (int i = 0; i < CRYPTO_NUM_LOCKS; i++) { > PR_DestroyRWLock(lockarray[i]); > } > } > > When i ran this under Intel Parallel Studio to check for race conditions > ,it gave a lot of race conditions in ssluse.c > > > View Source > > BIO *bio_out = BIO_new(BIO_s_mem()); > > ssl_seeded = TRUE; > > > Any idea what am i doing wrong? > > Thanks,<br> > Anurag Shukla > > > > > > > [1]: http://i.stack.imgur.com/hMuss.png
