Previous | Next --- Slide 14 of 70
Back to Lecture Thumbnails

There was a question here about what happens if the sender clears their buffer for "foo" after the call to "SEND(foo)". Someone said that you would end up sending garbage. Why is that the case?


@eknight7 The model we are working with here is that the send request happens asynchronously with the rest of the thread. When the SEND function is called, foo is copied to the buffer, and then when the send actually happens, whatever is in the buffer at the time is what is sent. If the parent thread modifies the buffer before the send actually occurs whatever happens to be in it at the time the SEND actually occurs is what will be sent, rather than the original message.


@PID_1, eknight7. I'd like to make a clarification on this discussion.

The calling thread populates a message buffer and then passes the buffer foo as an argument to send(). The message passing library will transfer the contents of the buffer foo. However, since this is an async send, the calling thread does not know when the send actually takes place. All it knows is that it will take place some point after the call to send and some point before a call to checksend() indicates the send is complete. Therefore, if the calling thread updates the contents of the buffer foo after the call to send but before confirming the message has been sent using the subsequent call to checksend(), then it's not defined what message actually got sent. The message might have been the contents of the buffer foo at the time of the call to send, the contents of the buffer after the calling thread made an update, or perhaps even a mixture of the two if the message was sent in the middle of the calling thread updating foo.


Does this mean that we have to statically determine that the message buffer is updated at the correct times or is there some other way to ensure this?


@althalus. I think we programmers need to well design the program to make sure not to modify the foo buffer after SEND and before CHECKSEND.