curl-library
答复: 答复: SSL and multithread crash on windows, how to use mutex on windows?
Date: Fri, 25 Nov 2016 13:10:05 +0000
Johan,Thank you very much!
________________________________
发件人: curl-library <curl-library-bounces_at_cool.haxx.se> 代表 Johan de Vries <devries_at_ixon.co>
发送时间: 2016年11月25日 2:03:03
收件人: libcurl development
主题: Re: 答复: SSL and multithread crash on windows, how to use mutex on windows?
Hello,
You only need to call the openssl_crypto_init_locks mentioned above once at the beginning of your program.
Met vriendelijke groet / Best regards / Mit freundlichen Grü?en,
Johan de Vries
Software Developer
[http://www.ixon.net/wp-content/uploads/2013/12/logo-default.png]
IXON
Vierlingsbeekseweg 52 A
5825 AX Overloon
the Netherlands
T +31 (0)85 744 1105<tel:%2B31%20%280%2985%20744%201105>
E devries_at_ixon.co<mailto:devries_at_ixon.co><mailto:devries%E2%80%8B_at_ixon.net>
I www.ixon.co<http://www.ixon.co/>
2016-11-25 10:50 GMT+01:00 mao mao <lmjrd_at_hotmail.com<mailto:lmjrd_at_hotmail.com>>:
Thankyou Thomas and Johan both
to Johan: how to use these two functions
openssl_crypto_locking_callback
openssl_crypto_init_locks
when start new thread using _beginthreadex or createthread or afxbeginthread?
________________________________
发件人: curl-library <curl-library-bounces_at_cool.haxx.se<mailto:curl-library-bounces_at_cool.haxx.se>> 代表 Johan de Vries <devries_at_ixon.co<mailto:devries_at_ixon.co>>
发送时间: 2016年11月24日 23:21:33
收件人: libcurl development
主题: Re: SSL and multithread crash on windows, how to use mutex on windows?
Using boost:
#include <boost/ptr_container/ptr_vector.hpp>
#include <openssl/crypto.h>
#define OPENSSL_THREAD_DEFINES
#include <openssl/opensslconf.h>
#if !defined(OPENSSL_THREADS)
#error OpenSSL needs to be compiled with thread support
#endif
boost::ptr_vector<boost::mutex> openssl_lock_list;
void openssl_crypto_locking_callback(
int mode, int type, const char * const, int
) {
if( mode & CRYPTO_LOCK ) {
openssl_lock_list[type].lock();
} else {
openssl_lock_list[type].unlock();
}
}
void openssl_crypto_init_locks()
{
for(int i = 0; i < CRYPTO_num_locks(); ++i) {
openssl_lock_list.push_back(new boost::mutex());
}
// Not neccessary according to docs, and boost can't really give a pointer or
// integer ID of a thread
// CRYPTO_THREADID_set_callback(openssl_crypto_threadid_callback);
CRYPTO_set_locking_callback(openssl_crypto_locking_callback);
}
Met vriendelijke groet / Best regards / Mit freundlichen Grü?en,
Johan de Vries
Software Developer
[http://www.ixon.net/wp-content/uploads/2013/12/logo-default.png]
IXON
Vierlingsbeekseweg 52 A
5825 AX Overloon
the Netherlands
T +31 (0)85 744 1105<tel:%2B31%20%280%2985%20744%201105>
E devries_at_ixon.co<mailto:devries_at_ixon.co><mailto:devries%E2%80%8B_at_ixon.net>
I www.ixon.co<http://www.ixon.co/>
2016-11-25 7:25 GMT+01:00 Thomas Glanzmann <thomas_at_glanzmann.de<mailto:thomas_at_glanzmann.de>>:
Hello,
> SSL and multithread crash on windows, how to use mutex on windows?
Best way is you post a striped down example which crashes.
For me the following works, without a problem.
Once:
curl_global_init(CURL_GLOBAL_DEFAULT);
For each thread:
_beginthread(...);
share = curl_share_init();
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_SHARE, share);
curl_easy_setopt(curl, CURLOPT_URL, "https://google.com");
curl_easy_perform(curl);
curl_easy_cleanup(curl);
Cheers,
Thomas
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-11-25