boost::asio::ip::tcp::socket est elle thread safe ?
bonjour, je voudrai ouvrir une connexion tcp depuis 2 threads differents, je vous poste une version simplifiée qui genere le segmentation fault ou un illegal instruction(SIGILL), c'est selon l'humeur :mouarf::
Code:
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
| unsigned short port = 6666;
char ipchar[200]= "127.0.0.1";
static void GLFWCALL launchThread1 (void * p) {
try {
boost::asio::io_service myIO;
boost::asio::ip::tcp::endpoint iaServer (boost::asio::ip::address::from_string(ipchar), port);
boost::asio::ip::tcp::socket clientSocket(myIO);
clientSocket.connect(iaServer); // c'est ici que ca plante
}
catch (std::exception& e) {
fprintf (stdout, "*********after connect1:%s\n", e.what());fflush(stdout);
}
catch (...) {
fprintf (stdout, "*********after connect2\n");fflush(stdout);
}
fprintf (stdout, "th1----\n");fflush(stdout);
}
int main () {
GLFWthread th1, th2;
glfwInit();
th1 = glfwCreateThread (launchThread1,NULL);
th2 = glfwCreateThread (launchThread1,NULL);
fprintf (stdout, "m1----\n");fflush(stdout);
glfwWaitThread (th1, GLFW_WAIT);
glfwWaitThread (th2, GLFW_WAIT);
fprintf (stdout, "mend----\n");fflush(stdout);
} |
à l'execution :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
Program received signal SIGSEGV, Segmentation fault.
[Switching to thread 3468.0x5b8]
0x015afedc in ?? ()
(gdb) bt
#0 0x015afedc in ?? ()
#1 0x00410fec in _Unwind_SjLj_RaiseException ()
at C:/Dev/boost/boost/asio/detail/call_stack.hpp:84
#2 0x0040804d in __cxa_throw ()
at C:/Dev/boost/boost/asio/detail/call_stack.hpp:84
#3 0x0041a106 in boost::throw_exception<boost::system::system_error> (
e=@0x17afd2c) at C:/Dev/boost/boost/throw_exception.hpp:64
#4 0x0041bfe0 in boost::asio::detail::throw_error (err=@0x17afd8c)
at C:/Dev/boost/boost/asio/detail/throw_error.hpp:36
#5 0x0041abae in boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::s
tream_socket_service<boost::asio::ip::tcp> >::connect (this=0x17afe0c,
peer_endpoint=@0x17afedc) at C:/Dev/boost/boost/asio/basic_socket.hpp:556
#6 0x0040150d in launchThread1 (p=0x3e2718) at testlexical.cpp:49
#7 0x00402568 in _glfwNewThread@4 ()
at C:/Dev/boost/boost/asio/detail/call_stack.hpp:84
#8 0x7c80b729 in KERNEL32!GetModuleFileNameA ()
from C:\WINDOWS\system32\kernel32.dll
#9 0x00000000 in ?? () |
Est-il possible que dans ces conditions la librairie ne soit pas thread safe ?
édit: testé sur un serveur qui répond, l'exception n'est pas levée, pas de segmentation
testé sur boost 1_41 et 1_42, gcc(mingw)3.4.5, et testé avec les boost::thread
les options de linkage:
-llibboost_thread-mgw34-mt-d-1_42 -llibboost_system-mgw34-mt-d-1_42
J'arrête pour aujourd'hui, ou je vais me tirer une balle dans la tête.
A l'aide :mrgreen: