[zeromq-dev] inproc: passing an object pointer between threads causing datarace?? (3.2.2 stable release)

Kah-Chan Low kahchanlow at yahoo.com
Thu Nov 29 13:18:21 CET 2012


Sorry, my last sentence should read " In this case,
is it possible for the program to output any value other than '6' for '*n'?"

Basically I declare n as an int*, and I allocate memory for *n, assign a value to *n, and send the pointer n.

int *n = new int; *n = 4; *n += 2; zmq_socket.send(&n, sizeof(n));

So the pointer value is valid when sending actually takes place.

________________________________
 From: Pieter Hintjens <ph at imatix.com>
To: Kah-Chan Low <kahchanlow at yahoo.com>; ZeroMQ development list <zeromq-dev at lists.zeromq.org> 
Sent: Wednesday, November 28, 2012 11:22 PM
Subject: Re: [zeromq-dev] inproc: passing an object pointer between threads causing datarace?? (3.2.2 stable release)
 
On Tue, Nov 27, 2012 at 10:23 PM, Kah-Chan Low <kahchanlow at yahoo.com> wrote:

> 1. I don't understand the error message above: how does accessing the value
> of variable n have anything to do with the internals of ZMQ?

It doesn't, as far as I can see.

> 2. Is it possible for the compiler to rearrange the machine instructions
> such that the assignment of value of n (i.e. *n=4; *n += 2;) occurs after
> the message has been sent and received on the other thread?  In this case,
> is it possible for the program to output any value other than '6' for 'n'?

That's very doubtful. However are you not declaring n on the stack?
Meaning, it will not be valid when the send actually happens.

-Pieter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20121129/f8270dea/attachment.htm>


More information about the zeromq-dev mailing list