czmq
czmq copied to clipboard
zsys_set_thread_name_prefix() is not valid after creating sockets
When compiling some test software using libzmq (version 4.3.4) & czmq (version 4.2.1) everything runs fine under Linux. Running the same software gives an error under Windows: zsys_set_thread_name_prefix() is not valid after creating sockets Although the software seems to run fine under Windows too. Reading the sources it seems the function is to be used under Linux only, but in my code i do not call this directly. Should i worry under Windows with this error ?
The problem seems to be related to automatic context creation inside czmq. When the first socket or actor is created and no context exists, it will internally create one. In my software at startup, there were multiple (own created threads, not using zactor) which initialized a socket. So the context creation was being done by one (or more) threads at the same time. I think a race condition exists with this in czmq. I solved the problem by creating the context up front, by putting at the start of main zsys_init(). This creates the context by the main thread, afterwards the other threads start creating sockets. Then the problem went away.
Did you also try adding zsys_init()
It seems it is fixed for you, so can we close this?
For me it worked by making sure zsys_init() is put as the first function to execute in main(). For me this issue can be closed, but i still have the feeling that the automatic context creation handled by czmq is not correct. Why do we need zsys_init()? It is a bit contradictory with the automatic context creation philosopy of czmq. The documentation gives you the feeling you do not need to worry about context creation, but to me this is not correct. At least not when using multiple threads which create sockets at the same time. I think the problem is that the automatic context creation inside czmq does not handle it correctly when multiple threads are involved.
I feel you. But we'd need to dive deeper to get to a compatible fix or better documentation. You case could also be an edge case. Perhaps some notes in the docs might help as well. We really appreciate PRs
This issue has been automatically marked as stale because it has not had recent activity for 90 days. It will be closed if no further activity occurs within 21 days. Thank you for your contributions.