[zeromq-dev] Fwd: Re: New Python bindings
Jon Dyte
jon at totient.co.uk
Mon Feb 15 09:39:18 CET 2010
On Monday 15 Feb 2010, Brian Granger wrote:
> Jon,
>
> > Is this is safe? After calling send, the msg is passed to an IO thread ?
> >
> > That means there are now two threads concerned with the lifetime of memory
> > of the string (python and the zmq io thread?)
>
> You raise a good point. I had forgot that the msg is not sent immediately.
>
> > I see you call zmq_msg_init_data with NULL for the free function, but
there is
> > still the case that the python thread could destroy the string before the
io
> > thread uses it? I would expect you to have to pass a free function,
> > and manipulate the string in send to increase the refcount, and the free
> > function to decrease the refcount.
>
> Yes, this is definitely the way to handle it. Thanks for catching
> this, I will fix this.
>
On the other hand it might be cheaper to just take the hit of the copy, as
using the ref count and free function, means the io thread would end up
calling into the python runtime, which might slow things down more and
possibly cause other threading issues.
Best,
Jon
More information about the zeromq-dev
mailing list