0

It shows in my multi-thread program: I starts about 300 thread to connect a game server using Websocket(libwebsockets), the main loop is: step 1 create a new context of websocket step 2 connect with server using websocket setp 3 destroy context using the function lws_context_destroy(to disconnect with server), and then return to step 1 after a while(after connected success about 5k times or more), my program crashed(100%), the stack info is listed below:

#1  0x00007f74a5106bd7 in doall_util_fn (lh=0x7f74781b1a20, use_arg=0, func=0x7f74a508ddc0 <def_cleanup_cb>, func_arg=0, arg=0x0) at lhash.c:294
#2  0x00007f74a508dd7c in int_cleanup () at ex_data.c:382
#3  0x00007f74a65ce76c in lws_context_destroy2 () from /usr/local/lib/libwebsockets.so.10
#4  0x00007f74a65cea74 in lws_context_destroy () from /usr/local/lib/libwebsockets.so.10

I am a newer to libwebsockets, do not know how to fix this... could any one give any tips? thx

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
moosedong
  • 21
  • 1

1 Answers1

1

Problem fixed. It seems that lws_context_destroy() is not a thread-safe function, lock it with a thread lock can fix this problem :

lock();
lws_context_destroy();
unlock();
moosedong
  • 21
  • 1