@@ -400,23 +400,26 @@ class wspp_callback_client : public websocket_client_callback_impl,
400
400
401
401
m_state = CONNECTING;
402
402
client.connect (con);
403
- m_thread = std::thread ([&client]() {
403
+ {
404
+ std::lock_guard<std::mutex> lock (m_wspp_client_lock);
405
+ m_thread = std::thread ([&client]() {
404
406
#if defined(__ANDROID__)
405
- crossplat::get_jvm_env ();
407
+ crossplat::get_jvm_env ();
406
408
#endif
407
- client.run ();
409
+ client.run ();
408
410
#if defined(__ANDROID__)
409
- crossplat::JVM.load ()->DetachCurrentThread ();
411
+ crossplat::JVM.load ()->DetachCurrentThread ();
410
412
#endif
411
413
412
414
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
413
- // OpenSSL stores some per thread state that never will be cleaned up until
414
- // the dll is unloaded. If static linking, like we do, the state isn't cleaned up
415
- // at all and will be reported as leaks.
416
- // See http://www.openssl.org/support/faq.html#PROG13
417
- ERR_remove_thread_state (nullptr );
415
+ // OpenSSL stores some per thread state that never will be cleaned up until
416
+ // the dll is unloaded. If static linking, like we do, the state isn't cleaned up
417
+ // at all and will be reported as leaks.
418
+ // See http://www.openssl.org/support/faq.html#PROG13
419
+ ERR_remove_thread_state (nullptr );
418
420
#endif
419
- });
421
+ });
422
+ } // unlock
420
423
return pplx::create_task (m_connect_tce);
421
424
}
422
425
@@ -648,10 +651,13 @@ class wspp_callback_client : public websocket_client_callback_impl,
648
651
649
652
// Can't join thread directly since it is the current thread.
650
653
pplx::create_task ([this , connecting, ec, closeCode, reason] {
651
- if (m_thread.joinable ())
652
654
{
653
- m_thread.join ();
654
- }
655
+ std::lock_guard<std::mutex> lock (m_wspp_client_lock);
656
+ if (m_thread.joinable ())
657
+ {
658
+ m_thread.join ();
659
+ }
660
+ } // unlock
655
661
656
662
// Delete client to make sure Websocketpp cleans up all Boost.Asio portions.
657
663
m_client.reset ();
0 commit comments