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 <[email protected]>
To: Kah-Chan Low <[email protected]>; ZeroMQ development list 
<[email protected]> 
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 <[email protected]> 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
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to