[zeromq-dev] Static zmq context in Windows DLL

Osiris Pedroso opedroso at gmail.com
Mon Dec 9 17:59:17 CET 2019


In a Windows Dll, that function is named DllMain. Look for it's
documentation, and there is an argument for when shutdown is happening.
But it's not necessarily always called, i.e. when TerminateProcess() is
called.

Best bet is to define s Singleton class, define it's instance within a
#pragma lib (which forces its initializer to be executed before anything
else and it's destruction to be the last thing happening.

On Mon, Dec 9, 2019, 17:23 Simon Giesecke <simon.giesecke at gmail.com> wrote:

> Hi,
>
> The problem will be that the destruction order is not what you expect it
> to be.
>
> I think overall, the least painful way to address this is to not use a
> global static zeromq context in your DLL, and rather pass one instance
> explicitly to all objects that require it.
>
> If you really don't want to go this way, one alternative is that your DLL
> exposes a shutdown function to the application, which calls that shutdown
> function when it exits. The shutdown function then closes the global static
> zeromq context. (This is what the mentioned zsys_shutdown function does for
> czmq)
>
> Best wishes
> Simon
>
> On Mon, Dec 9, 2019 at 2:16 PM Attila Magyari <atti86 at gmail.com> wrote:
>
>> Hello,
>>
>> I've encountered this issue: https://github.com/zeromq/czmq/issues/1788
>> Basically when exiting the application, I get this error: *Assertion
>> failed: Successful WSASTARTUP not yet performed.*
>>
>> I am using ZeroMQ on windows inside a DLL. I have a global static zeromq
>> context, because I want it persistent across multiple instances of my
>> objects, and there is no central place I could pass it from otherwise.
>>
>> The proposed solution is to call zsys_shutdown() before exiting the
>> application, but I don't know how and where:
>>
>>    - This function is not available through the API that I am using
>>    (zmq.h/zmq.hpp)
>>    - Not sure where would I call it, as I don't know when the
>>    application exits. In my library there is no main object that could control
>>    the lifetime of the zmq layer
>>
>> Any idea how to approach this?
>>
>> Kinds regards,
>> Attila
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
>
>
> --
>
> Dr.-Ing. Simon Giesecke
> Lehmbruckstr. 18 - 10245 Berlin (Friedrichshain)
> Tel.: 030-29360491
> Tel.: 0179-6868999 (Mobil)
> E-Mail: simon.giesecke at gmxpro.de
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20191209/e439ca6b/attachment.htm>


More information about the zeromq-dev mailing list